scriptObject retrieval in AngelScript

Hello, I’m getting an error while trying to access the scriptObject from a ScriptInstance component:

ScriptInstance@ scriptInstanceCmp = result.node.GetComponent(“ScriptInstance”);
Print(scriptInstanceCmp.className);
currentSelectedCharacter = cast<BaseCharacter>(scriptInstanceCmp.scriptObject);

The 2nd line prints out fine while the 3rd line gives a null reference error from angelscript.

This is my global “gamemode” script where I include different .as files for the BaseCharacter. I already marked all my classes as shared so they should be seen across modules as I understand.

Any ideas on what I could be missing - Thanks in advance!
Trevor

You don’t specify what type you’re casting to.

Sorry. I do in fact have them - Forgot to escape the “<” in the forum editor. - Updated

Another reason could be that some types require using @ prefix for handle assignment.
(see https://urho3d.github.io/documentation/HEAD/_scripting.html#Scripting_Modifications)

Try something like:
@currentSelectedCharacter = cast<BaseCharacter>(scriptInstanceCmp.scriptObject);

That was it.
Thanks Enhex!

PS. You could use [v] button to mark answer as solution instead of changing title.

2 Likes