0 votes

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.

in Engine by (23 points)
retagged by

1 Answer

0 votes
Best answer

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;
by (23 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.