How to target one instance of a scene and change that one instance rather than all of them within a script

Godot Version

4.2.2

Question

Currently working on a card game, but since cards overlap the detection for hovering them is small. This also means that the top card which should have full detection doesnt. Modifying the specific card’s CollisionBox2D resizes all of them. Is there any workaround or way to do this?

The collision shape is a resource, meaning the problem likely stems from you modifying a resource that is shared by every card. If each card is a node created in the editor, you can just make new resources for each. If you are creating them through a script, a possible fix could be making a new resource for each in code. I haven’t done the latter before, so I’m not entirely sure if it’s possible or would work though. Hope this helps in some way!

go into the card object, select the collisionBox2d and then set the flag “local to scene”, which makes them all unique if they are instantiated multiple times into the scene (like having multiple cards in your hand).

how do i do this? i’m pretty new to godot, sorry

edit: i made the shape within collisionbox2d local to scene but it didnt seem to fix it. for reference heres the code i want to run:

func _ready():
	$HoverArea/CollisionShape2D.shape.set_size(Vector2(32, 88))
	$HoverArea/CollisionShape2D.position = Vector2(0, 20)

edit 2: fixed it im stupid :sob: forgot an if statement

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