Why would 2 nodes of the same Instance share the value of an export var even when it's different ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By looote

In a scene "model " of a KinematicBody2D with a CollisionShape2D (shape is a Circle)
The script is :

extends KinematicBody2D
onready var collision = $CollisionShape2D
export var SIZE = 0
func _ready():
	collision.shape.set_radius(SIZE)

In a scene “world” i have 2 instance of “model”:

  • one with SIZE = 50
  • one wit SIZE = 100

Then why the size of the collision is the same for both ? (50 or 100, depending of the order in the tree) is this supposed to work like that ?

I am new to godot and coding in general so maybe i’m all wrong.

I cant reproduce that behaviour… can you provide you project-folder?

whiteshampoo | 2020-05-28 06:07

Here is the project
Here is the result

looote | 2020-05-28 10:53

:bust_in_silhouette: Reply From: whiteshampoo

Your shape in you CollsisionShape2D (the CircleShape2D) is the SAME in each instance. This is not an property, but kind of an object. I hope you understand what i’m trying to say.
If you want to handle it with the radius, just remove the CircleShape2D (or leave it, if the warning annoys you) and add new CircleShape2D in your ready-method:

func _ready():
	collision.shape = CircleShape2D.new()
	collision.shape.set_radius(SIZE)

Yes i understand.
Thank you.

looote | 2020-05-28 11:47

Or you can just press make unique from the dropdown menu in the inspector.

Panagiotis Halatsako | 2020-05-28 12:36