Search code examples
inheritanceoverridingangelscript

Angelscript calling overriding function from object in array


I have noticed that if you have an array of a class and put in an object that inherits from said class and try to call the overriding function from a for loop it runs the overridden function

example:

class Entity{
    void Update(){
        print("A");
    }
}

class Player : Entity{

    void Update() override{
        print("B");
    }
}

array<Entity> entities;
void main(){
    Player p;
    entities.insertLast(p);
    entities[0].Update();
    p.Update();
}

output:

A
B

Solution

  • My angelscript-foo is a bit rusty, but i think you need array<Entity@> here.