godot icon indicating copy to clipboard operation
godot copied to clipboard

Add a warning for when the scene root node is transformed

Open aaronfranke opened this issue 2 years ago • 4 comments

This is a low priority PR, but I think it's a good idea.

This PR adds a configuration warning for when the root node has a transform. This is usually a mistake when saving a branch as a scene, or having the wrong node selected when doing transform operations. Instances of the scene will set their own transform, so it's best practice to not have the root be transformed.

Screenshot 2023-09-18 at 5 31 02 PM

aaronfranke avatar Sep 19 '23 01:09 aaronfranke

The first commit in this PR is just code organization. It does not make much sense for the configuration warning string formatting to be in Node, since this is only needed in the editor.

Note that this may change if we do decide to print node configuration warnings in a running project (when debugging is enabled). This is something I've considered at some point, as it can help with difficult-to-diagnose runtime-only issues without requiring code duplication. See https://github.com/godotengine/godot-proposals/issues/3004.

Calinou avatar Sep 25 '23 16:09 Calinou

I'm personally not a fan of this. I believe warnings should be reserved for when the configuration of a node results in behavior that in all circumstances is not correct (like a collision without a node that derives from it). I don't see anything objectively wrong with changing the transforms of a root node, as long as instantiations of it are handled correctly such as in the above-mentioned PR.

ryevdokimov avatar Jan 23 '24 15:01 ryevdokimov

The warning isn't entirely correct. Most often only position is overriden, e.g. when dropping the scene into viewport.

KoBeWi avatar Mar 02 '24 17:03 KoBeWi

The warning isn't entirely correct. Most often only position is overriden, e.g. when dropping the scene into viewport.

I would argue that if users want a scene to have inherent scale or rotation, they should instead scale or rotate the child nodes. This way this inherent scale or rotation will not be discarded if the user sets node.transform on the scene root.

If a user sets a scene's scale to be (2, 2, 2), it's expected that the scene should get bigger by a factor of 2. If the original scene had a root node scale of (10, 10, 10), this would result in the scene getting smaller by a factor of 5.

aaronfranke avatar Aug 04 '24 05:08 aaronfranke

Isn't this (at least partially) superseded by #80561?

KoBeWi avatar Oct 03 '24 02:10 KoBeWi

@KoBeWi They are separate things, but you are correct that there is a partial overlap. However, this PR covers the case of a user accidentally transforming their scene's root node.

aaronfranke avatar Oct 03 '24 06:10 aaronfranke

So I'm not sure about the warning itself, but the implementation is fine. Except the warning does not update when you transform the node; you have to save the scene or update warnings in other way. Is that expected behavior?

KoBeWi avatar Oct 19 '24 12:10 KoBeWi

@KoBeWi Yes, I noticed that too. It's a minor problem, I think it's fine, unless someone knows how to fix it.

aaronfranke avatar Oct 30 '24 11:10 aaronfranke

It's confusing when you reset transform, but the warning is still there. At least mention in the warning that clearing it requires scene reload.

KoBeWi avatar Oct 30 '24 11:10 KoBeWi

Thanks!

Repiteo avatar Dec 20 '24 02:12 Repiteo

@aaronfranke As part of my configuration info refactor #90049 I need to somehow integrate this into the new system.

Was there any particular reason the checks and warnings were added to SceneTreeEditor, instead of adding them as normal configuration warnings on the Node2D and Node3D classes?

I assume it was because get_configuration_warnings is available outside of editor? If so, the new system is guarded by TOOLS_ENABLED so it would only run in editor. Which means I could move your code into both node classes.

RedMser avatar Jan 22 '25 17:01 RedMser

@RedMser This was done because the warning is only valid for the scene root node, not just any Node2D/Node3D.

Also, in general, I would be interested in having less editor-specific stuff inside of non-editor classes, even if guarded by TOOLS_ENABLED, not more.

aaronfranke avatar Jan 22 '25 17:01 aaronfranke

I can see where you're coming from, but I really don't like the thought of having the list of configuration info populated from multiple different sources. It's already tedious to follow the inheritance chain for config warnings, but having to now also check a separate function as an additional source of warnings doesn't seem great to me.

Sadly I don't have a proposal for a solution that makes both of us happy. Especially with how Resource would now also get config info, which means more editor-specifics in these classes...

RedMser avatar Jan 22 '25 18:01 RedMser

tbh you can check whether the node is scene root from within the node, by using get_tree()->get_edited_scene_root().

KoBeWi avatar Jan 22 '25 19:01 KoBeWi