Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any reference to a node that was script assigned with SetScript (), is invalid #45602

Open
Torguen opened this issue Jan 31, 2021 · 1 comment

Comments

@Torguen
Copy link

Torguen commented Jan 31, 2021

Godot version:

3.2.4 rc1 mono

OS/device including version:

win10 64

Issue description:

A node is lost when a script is assigned to it with "SetScript ()".
References to that node will not be valid.
Normally the run window closes immediately when it appears and nothing else happens, however sometimes the editor shows this error:

Captura3

If line 13 is commented out, then no error occurs.
On the other hand, if line 13 is commented, it can be seen in remote mode that the "script" property is displayed duplicated.

Captura2

Steps to reproduce:
Create a class without code.
Create a node, for example of type Node.
Create a script and in _Ready create a new node type object.
Then assign it the initial script that had no code.
Call "SetProcess (true)" of the newly created node.
Run.
The run window will close automatically at startup, but may occasionally the editor shows the initial image error.
Test project code, line 13 causes the error:

Captura4

Captura2

Minimal reproduction project:

TestSetScript.zip

@Torguen Torguen changed the title "SetProcess( true )" does not work with a node that has been assigned a script. Any reference to a node that was script-assigned with SetScript (), is invalid Jan 31, 2021
@Torguen Torguen changed the title Any reference to a node that was script-assigned with SetScript (), is invalid Any reference to a node that was script assigned with SetScript (), is invalid Jan 31, 2021
@31
Copy link
Contributor

31 commented Jun 9, 2021

The ObjectDisposedException is expected behavior. When you call SetScript on nodo, nodo isn't valid anymore. See #31994 (comment) for more details, and a way to get a reference to the new node that Godot creates when you call SetScript.

However, in most cases you don't actually need SetScript, anyway. It looks like you can just call new ScriptSetted(), which is a lot simpler:

nodo = new ScriptSetted();
AddChild(nodo);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants