Tool script variables save but reset when reloaded

Godot Version

4.3.stable

Question

Hey, folks!

Having a weird problem with a tool script I’m writing. My script is put onto a prop in my scene (a track light, in this case) to rotate the transform of a child that’s hidden from the scene’s hierarchy. This works in the editor, and when I save the scene, I see those values are serialized in the scene file. However, when I then run the game, those values are reset. And when I close and open the scene, the values are reset there, too.

I’ll break it down.

To Reproduce

  • First I create a 3D scene for the tracklight. I put a model in for the base, and I put a model in for the pivoting head. To that, I add a light.

  • On the parent node for this scene, I attach a script (set as a @tool only so I can see it update in the scene view):

    @tool
    class_name PropTracklight
    extends Node3D
    
    @export var edit_mode: bool = false
    
    @export_category(“Light Aim”)
    @export_range(-180, 180) var yaw: float = 0:
        get:
            return yaw
        set(value):
            if head and value != yaw and edit_mode == true:
                yaw = value
                head.rotation_degrees.y = yaw
    
  • I add this new PropTracklight scene into a gameplay scene. I check edit_mode, update the yaw, then uncheck edit_mode and save the scene.

  • I see that this value has been saved into the scene file as expected:

    [node name="PropLightTracklight" parent="." instance=ExtResource("45_ugi5v")]
    transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4.53808, 2.82554, -7.80749)
    yaw = 32.727
    
  • I run the game, look at the light, and see that it’s been reset.

  • Back in the editor, I load a different scene, then back to the scene where I placed the tracklight. The light’s yaw has reset. But the scene still has that yaw value set. So this seems like the ID of my tracklight node changes?

What’s the solution, here? Is this a bug or expected behavior?

Thanks for any advice!

Enable “editable children” for the instance you want to save changes for.

:person_facepalming: Of course. I’m super over-complicating things.

Thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.