Hi there. I wonder how I can make an exported variable, of any kind, Vector3, int, whatever, to be shared between all instances. Just like a resource.

Thanks

  • xyz replied to this.
  • while-free- Export a reference to the resource itself in the top node.

    @export box: BoxShape3D

    Now just copy-paste the resource from the CollisionShape3D node to this property and you'll be able to edit it directly on the instance without needing any proxy properties or a tool script.

    while-free- If you declare a class property static it will be shared between instances. Afaik static properties cannot be exported. But why just not use a resource?

      xyz I'm trying to export some variable in a child node, and to do so, I've declared an exported variable inside the root node. Using setter and getter methods I'm updating the child node. But the update does not reflect inside the editor.

      I have used @tool to make it update in the editor too. But the variable in the root node is local to instances, and the child node (CollisionShape3D) is a shared resource. Updating the value in an instance inspector does change the child for all instances, but the numbers inside the inspectors remain different.

      Using Engine.is_editor_hint inside _process function, I've managed to update the numbers as well, however if I change the number in an instance in another scene and save the project and exit, the values set in the main scene itself will overwrite the values set in the instances. Because I haven't navigated to the main scene before exiting and the _process (and _ready) has not been called.

      I'm new to Godot... so sorry if there is any stupidity in my workflow xD

      But here are the codes:

      @tool
      extends Area3D
      
      @export var size = Vector3.ONE:
      	get:
      		return size
      	set(value):
      		size = value
      		if not is_inside_tree():
      			await ready
      		get_node("CollisionShape3D").shape.size = size
      
      func _ready():
      	if Engine.is_editor_hint():
      		if size != get_node("CollisionShape3D").shape.size:
      			size = get_node("CollisionShape3D").shape.size
      			print("ready")
      
      func _process(_delta):
      	if Engine.is_editor_hint():
      		if size != get_node("CollisionShape3D").shape.size:
      			size = get_node("CollisionShape3D").shape.size
      			print("process")
      • xyz replied to this.

        while-free- This sounds too complicated and you're confusing nodes and resources. CollisionShape3D is a node not a resource.

        Your problem description is very abstract. Since I don't have much capacity for abstractions 😉 why don't we take a step back and you describe what's your final practical goal with this. What do you want to make?

          xyz My bad. CollisionShape3D gets a BoxShape3D which I guess is a resource. However it doesn't matter much, because it's shared between the instances and that's the point.

          My final goal is to make the size of the BoxShape3D (child of Area3D) editable inside the inspector, without the need to make the children editable in the editor. I want the change to be reflected in the viewport immediately, showing me the bounding box of the BoxShape3D. And I want the exported value to update inside all the instances in the scene immediately.

          The problem for the moment is that everything works fine, expect the exported value in the Area3D node. I think the explanation of my previous post now makes sense.

          In a nutshell: how am I supposed to make a property of the child node be exposed at the top-level parent.

          Thank you for trying to help me! 🙂

          • xyz replied to this.

            while-free- Export a reference to the resource itself in the top node.

            @export box: BoxShape3D

            Now just copy-paste the resource from the CollisionShape3D node to this property and you'll be able to edit it directly on the instance without needing any proxy properties or a tool script.

              xyz Clever solution! Thanks a ton! My thinking workflow is still polluted by Unity experience. I wonder when I will get rid of all that! xD

              • xyz replied to this.

                while-free- My thinking workflow is still polluted by Unity experience

                I know, we get a lot of this as of lately. Don't worry though, we have the means to reeducate you lot 😛