I am trying to create an AngelScript object that inherits from an interface defined in c++. When it is created in c++ I can not cast it, but when its created in AngelScript I can cast it. My AngelScript Player class that inherits the interface BaseEntity that is defined in C++;
class Player : BaseEntity
{
Player()
{
}
}
My test script
#include "Player.as"
void Run()
{
BaseEntity@ gameCreated = entity.CreateEntityByName("player");
BaseEntity@ localCreated = Player();
Player@ castedGameCreated = cast<Player>(gameCreated);
print("castedGameCreated");
if( castedGameCreated !is null )
{
print(" is a player\n");
}
else
{
print(" is not a player\n");
}
Player@ castedLocalCreated = cast<Player>(localCreated);
print("castedLocalCreated");
if( castedLocalCreated !is null )
{
print(" is a player\n");
}
else
{
print(" is not a player\n");
}
}
CreateEntityByName c++ function
asIScriptObject *EntityManager::CreateEntityByName(std::string &ent)
{
printf("CreateEntityByName\n");
ScriptEngine *sEngine = ScriptEngine::GetScriptEngine();
asIScriptEngine *engine = sEngine->GetEngine();
asIScriptContext *m_context = engine->CreateContext();
asIScriptModule *BaseEntityModule = sEngine->BuildScript("Player", "Player.as");
asIObjectType *type = engine->GetObjectTypeById(BaseEntityModule->GetTypeIdByDecl("Player"));
int funcid = type->GetFactoryIdByIndex(0);
m_context->Prepare( funcid );
m_context->Execute();
asIScriptObject *m_scriptObject = static_cast<asIScriptObject *>(m_context->GetReturnObject());
return m_scriptObject;
}
The output of the tester script is castedGameCreated is not a player castedLocalCreated is a player Am I creating the object incorrectly?