How to only change latest instanced scene's property?

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

So, when changing an instanced scene’s property cause all previous instanced scenes instead of the latest one.
GIF Here

Here’s the simplified instancing code I use

var my_scene = preload("res://myScene")
m = my_scene.instance()
m.position = position

i think you have to provide the full code. Where do you preload the scene? Usualy you will do this only once on startup, then use the preloaded scene later to instanciate.

Also i’m quit sure that you have to first add it as a child, wait for it to be “ready” and then you can change the position property.

klaas | 2021-07-06 17:01

export(PackedScene) var Projectile = preload("res://scripts/projectile/Projectile.tscn")

func shoot() -> void:
    if Input.is_action_pressed("player_shoot") and $ShootDelay.is_stopped():
	    var p = Projectile.instance()
	    physical_property.move_direction = pivot.global_rotation
	    physical_property.rotation = pivot.global_rotation
	    p.init(pivot.global_position, physical_property, property)

Here’s the code
The init function is a custom function.

Multirious | 2021-07-07 06:47

I dont see any problem here. How do you move your projectiles?
It looks like you are moving the projectile container instead of the individual

klaas | 2021-07-07 07:58

I don’t know. I just guessing that somehow the init function is setting every instance instead of one.
The projectile is moving using the data in the init function.
Also, doesn’t use the init function still getting the same result.

Multirious | 2021-07-07 08:02

So, its not your code and you dont know where the projectiles are moved?

I think th problem has nothing to do with the instancing but with the movement
code instead.

klaas | 2021-07-07 08:07

func move(delta) -> void:
    var x = cos(physical_property.move_direction)
    var y = sin(physical_property.move_direction)
    var direction: Vector2 = Vector2(x, y)
    var velocity: Vector2 = direction * physical_property.move_speed

    var collider = move_and_collide(velocity * delta)

Well, this is how its move.

Multirious | 2021-07-07 08:10

func init(pos: Vector2, projectile_physical_property, projectile_property) -> void:
    position = pos
    var start_pos = pos
    physical_property = projectile_physical_property
    property = projectile_property

Here’s init function.

Multirious | 2021-07-07 08:13

what is “physical_property” comming from?

I think you share this object in every projectile (as reference). So if you change this values every bullet changes its direction.

klaas | 2021-07-07 08:17

ahh, that’s probably why. The dictionary is referencing instead of getting value.

Multirious | 2021-07-07 08:20

How to fix this now?

Multirious | 2021-07-07 08:20

you can either dont use a dictionary or duplicate the dictionary

Dictionary — Godot Engine (stable) documentation in English

klaas | 2021-07-07 08:22

Stop using a dictionary probably a no from me, there’s a ton of variables inside that need to often pass around and use in the game. So, duplicate the dictionary. Thanks, again?

Multirious | 2021-07-07 08:28