Archive 17/01/2023.

scriptObject retrieval in AngelScript

TrevorCash

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

Enhex

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

TrevorCash

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

Enhex

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);

TrevorCash

That was it.
Thanks Enhex!

Eugene

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