My goal is to generate a solar system with a random number of planets and a sun. Planets are rigid bodies, the sun is a static body. I managed to make planets spawn by code. The radious of a planet should be 1024 * scale, where scale is a float between 0 and 1. I managed to do that too for the Sprite child node of the planets. The problem is that whenever i change the radius of the collision shape of a planet, the collision shape of the planets i modified before changes too in the same way. The result is that only the last planet i make spawn has the right collision shape radius. I cant see why is that, i think i'm doing something wrong but i really can't see what.
This is how i generate systems in the mainScene:
func generateSystem():
#add sun
var sun = sun_class.instance()
sun.set_pos(get_global_mouse_pos())
gravity_objects.push_back(sun)
add_child(sun)
#add planets
var last_size = 0
var nplanets = randi() % 8 + 3
for i in range(nplanets):
var planet = planet_class.instance()
var scale = i + 1
planet.init(gravity_objects, scale)
var ang = randf() * 360
planet.set_pos(Vector2(cos(ang), -sin(ang)) * 4000 * (i + 1))
add_child(planet, true)
pass
This is the init function inside the planet scene:
func init(Gravity_objects, scale):
gravity_objects = Gravity_objects
set_mass(get_mass() * scale)
#I tried this way too, the result is the same
#var shape = CollisionShape2D.new().set_shape(CircleShape2D.new().set_radius(1024 * scale))
#add_child(shape)
var shape = get_node("CollisionShape2D").get_shape(); shape.set_radius(1024 * scale)
get_node("Sprite").set_scale(Vector2(1, 1) * scale)
print(scale)
pass
This is the planet scene:

This is the mainScene:

This is the result, the blue circles rapresents the actual collision shape, the black circles with white ring are the sprite of the planets:

Thanks in advance.