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

Creating and Saving Mono Nodes Fails #27095

Open
shartte opened this issue Mar 15, 2019 · 4 comments
Open

Creating and Saving Mono Nodes Fails #27095

shartte opened this issue Mar 15, 2019 · 4 comments

Comments

@shartte
Copy link
Contributor

shartte commented Mar 15, 2019

Godot version:
3.1

Issue description:
Given a C# class "NodeScript" which inherits from Node, I expected the following to work:

var node = new NodeScript();
        
var packedScene = new PackedScene();
packedScene.Pack(node);

var restoredNode = (NodeScript) packedScene.Instance();

But the restoredNode loses the association with NodeScript upon being loaded. When I save the PackedScene to a file (my actual intent), I also see that the Node is saved with a CSharpScript association, but no actual association to the subclass.

I think the saved scene exhibits #17689, but the underlying issue is that the Ctor of NodeScript doesn't actually associate the right script with the node.

Minimal project:
ScriptChange.zip

@shartte
Copy link
Contributor Author

shartte commented Mar 15, 2019

After debugging this a little further, CSharpScript::create_for_managed_type does not set the path of the created Script instance. Indeed at runtime, it really can't.
A proper fix probably requires #15661.

@raulsntos
Copy link
Member

Can anyone still reproduce this issue in Godot 3.5 or any later release?

I've been unable to reproduce with the provided MRP in v3.5.stable.mono.official [991bb6a].

@neikeq
Copy link
Contributor

neikeq commented Aug 27, 2022

I would be surprised if this was fixed in 3.x as the presumed cause of the bug should still be there: scripts created from C# (new Class()) don't have a path assigned.
This should be fixed in master already, though, as we re-use the same script that's loaded from disk: 67db899.

@raulsntos
Copy link
Member

raulsntos commented Aug 27, 2022

Oh, I misunderstood the reproduction steps. It's still happening in 3.x indeed. It results in the following scene:

[gd_scene load_steps=2 format=2]

[sub_resource type="CSharpScript" id=1]

[node name="" type="Node"]
script = SubResource( 1 )

I can confirm it's fixed in master and it results in the following scene:

[gd_scene load_steps=2 format=3]

[ext_resource type="Script" path="res://NodeScript.cs" id="1_yfurm"]

[node name="" type="Node"]
script = ExtResource("1_yfurm")

@raulsntos raulsntos modified the milestones: 4.0, 3.x Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants