C# - getting script of instantiated node into variable

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Matěj Husák

Hello,
I need to get an script from a node, that I instantiated.

I tried those solutions:

hex hexScript = newHex as hex;

It returned error that Spatial can’t be converted to my hex script.
Or this:

hex hexScript = (hex)newHex.GetScript();

Basicly my question is: How can I get script of node into code → I need to change its behavior. It is map for game that has hexagonal tiles and each hex has own script and I’m setting it’s properties right from mapGenerate method.

:bust_in_silhouette: Reply From: Matěj Husák

Solution: I did find solution for my problem. Actually, it is not possible to get script straight from Spatial, but it works when you try to get it from node.

  1. Convert your spatial into a node variable

  2. Convert to your script from node

Code example:

Node hexScriptNode = newHex as node;
hex hexScript = hexScriptNode as hex;