I'm working on a game engine, using AngelScript. I have registered my entity class to AngleScript (there is no constructor on purpose, I don't want users to be able to declare new entities):
r = engine->RegisterObjectType("Entity", 0, asOBJ_REF); assert(r >= 0);
r = engine->RegisterObjectBehaviour("Entity", asBEHAVE_ADDREF, "void f()", asMETHOD(Entity, AddRef), asCALL_THISCALL); assert(r >= 0);
r = engine->RegisterObjectBehaviour("Entity", asBEHAVE_RELEASE, "void f()", asMETHOD(Entity, ReleaseRef), asCALL_THISCALL); assert(r >= 0);
r = engine->RegisterObjectMethod("Entity", "Transform& getTransform()", asMETHOD(Entity, get<Transform>), asCALL_THISCALL); assert(r >= 0);
I've also registered my Transform component:
r = engine->RegisterObjectType("Transform", sizeof(Transform), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLFLOATS); assert(r >= 0);
r = engine->RegisterObjectProperty("Transform", "Vec2 position", asOFFSET(Transform, position)); assert(r >= 0);
r = engine->RegisterObjectProperty("Transform", "Vec2 scale", asOFFSET(Transform, scale)); assert(r >= 0);
r = engine->RegisterObjectProperty("Transform", "float rotation", asOFFSET(Transform, rotation)); assert(r >= 0);
(My Vec2 is also registered, and I can confirm that it works).
I've added a global object to each script for the entity that it is sitting on:
r = engine->RegisterGlobalProperty("Entity entity", entity); assert(r >= 0);
entity (the one that I am passing into RegisterGlobalProperty()) is a pointer to the entity that the script is sitting on. So, if entity is a pointer, and getTransform() is returning a reference, then why doesn't the following set the entities position from a script?
entity.getTransform().position.x = 25.0f;
What am I missing? getTransform() works from native C++, so why isn't it working here?