I've declared an object type in AS:
class MyMsg : IMessage
{
int iValue = 0;
}
IMessage is just an empty interface. Now I want to send that message to another object with a delay:
MyMsg msg;
msg.iValue = 42;
GetObject().PostMessage(msg, 0.5);
PostMessage is implemented on the C++ side and now needs to duplicate the object, so that it can return to the script and let msg get destroyed, because it was created on the stack.
The function is registered like this:
RegisterObjectMethod("GameObject", "void PostMessage(const ezAngelScriptMessage& in, float delay)", asFUNCTION(GameObject_PostMessage), asCALL_GENERIC));
Now I wanted to use asCScriptEngine::CreateScriptObjectCopy to make a copy, but it always returns nullptr. The documentation says “This only works for objects, for primitive types and object handles the method doesn't do anything and returns a null pointer.” However, as far as I understand it, this IS an object, not a handle.
I've even tried this, to “fix” the type;
auto pArgType = pGen->GetEngine()->GetTypeInfoById(pGen->GetArgTypeId(0));
const char* szTypeName = pArgType->GetName();
auto pArgType2 = pGen->GetEngine()->GetTypeInfoByName(szTypeName);
void* pMsgCopy = pGen->GetEngine()->CreateScriptObjectCopy(pAsMsg, pArgType2);
The two types are different, so something is going on, but even with the second type, it doesn't work.
Stepping through the code, it ultimately ends up in asCScriptEngine::CreateScriptObject where it fails because objType->beh.factory == 0.
I don't get, why there shouldn't be a factory for this? I can instantiate other classes that are declared in scripts, without anything else declared (constructor or so).
Any idea what might be the problem?