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

Node type doesn't change to script's #85485

Closed
adamscoble opened this issue Nov 28, 2023 · 5 comments
Closed

Node type doesn't change to script's #85485

adamscoble opened this issue Nov 28, 2023 · 5 comments
Labels

Comments

@adamscoble
Copy link

Godot version

v4.2-beta6

System information

Windows 10

Issue description

If I add a script to a Node, the Node's type doesn't update according to the script. So if I change the script to inherit a Node3D instead of Node, the Node itself doesn't update its type (or at least the icon doesn't change to indicate it has).

Steps to reproduce

  • Create a script that inherits Node.
  • Add it to a Node.
  • Change the script to inherit Node3D.
  • The Node remains white/a Node (though does show the correct hierarchy in the inspector).

Minimal reproduction project

N/A

@Deozaan
Copy link

Deozaan commented Nov 29, 2023

I believe this is intentional due to bug reports about the opposite problem (changing the node type but not the script type): #79203

You need to right-click the node in the scene hierarchy and change its type.

@YuriSizov
Copy link
Contributor

YuriSizov commented Nov 29, 2023

To add to that, a script extending Node3D wouldn't work on a node of a more general type. The node has no idea about more specific methods and properties this introduces.

Only the other way around is possible.

@YuriSizov YuriSizov closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2023
@adamscoble
Copy link
Author

To add to that, a script extending Node3D wouldn't work on a node of a more general type. The node has no idea about more specific methods and properties this introduces.

Isn't this the issue though, that I can have a script extending Node3D on a Node and it's not immediately obvious why it's not working?

Genuine question: what use cases are there for having a script be a different type to the Node? I'm not sure I understand the presented case in the issue Deozaan linked. How is behaviour managed in the relationship? e.g.: if you put a script extending CharacterBody3D on a plain Node, is the resulting behaviour defined?

@YuriSizov
Copy link
Contributor

YuriSizov commented Nov 29, 2023

Isn't this the issue though, that I can have a script extending Node3D on a Node and it's not immediately obvious why it's not working?

It should be obvious when you run the scene, there should be an error. I agree that it would also be good to show some kind of warning in the Scene dock as well in this case.

what use cases are there for having a script be a different type to the Node?

If your script is of a broader type than your node (e.g. script is Node3D and node is CharacterBody3D) then the script is completely functional, it's just limited to a subset of the API accessible by that broader type. This is because the node of the CharacterBody3D inherits Node3D, so it has access to all of its methods and properties. It's useful when you want to share some basic functionality between differently typed nodes.

if you put a script extending CharacterBody3D on a plain Node, is the resulting behaviour defined?

This is the same as your original issue, it's not supported and has no sensible definition. If your node is Node3D and your script is CharacterBody3D, then your script has access to methods and properties which do no actually exist on the node.

@adamscoble
Copy link
Author

@YuriSizov thanks for indulging me! I think a warning in the Scene dock is probably the ticket here. I stumbled across this because I was inheriting from Node. However, later realised I needed access to 3D-world methods and changed it to inherit Node3D. Obviously the Scene I'd saved with the script (single Node with the script on it) obviously didn't update. A little warning icon if the script is attached to an incompatible type would make sense. Thanks again!

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

No branches or pull requests

3 participants