• Godot Help
  • Multiple instances of the same scene seem to be affecting each other

This may be due to my lack of knowledge about Godot, but I have a scene that represents a ColorRect and area2D. I have extended a variable from this scene to determine the sizes of both of these nodes, so in theory I could change the size on command. Here is the relevant pieces of code from this scene.

var CBOXSIZE = {
	"SINGLE" : Vector2(110,145),
	"SIDE" : Vector2(145,110),
	"MOD" : Vector2(450,145),
	"MAIN" : Vector2(145,145),
	"CONTROL" : Vector2(357,145),
	"HAND" : Vector2(89,1024),
	"NONE" : Vector2(10,10)
}
export(String, "SINGLE","CONTROL","MOD",'SIDE','HAND','MAIN','NONE') var triggerSize = 'NONE'

func _ready() -> void:
	$ColorRect.rect_size = CBOXSIZE[triggerSize]
	$Area2D/CollisionShape2D.position = CBOXSIZE[triggerSize]/2
	$Area2D/CollisionShape2D.shape.extents = CBOXSIZE[triggerSize]/2

When I add two instances of the above to my main scene, the color rects do in fact change to the correct sizing, but I am finding that the Area2D is being set the same across all instances in my main scene. It is in fact using the sizing set for the last node in the tree. This tells me that I'm misunderstanding something.

In the above image, the area2d was set to SIDE, and the one below set to MOD. Both A2D's seem to be referencing MOD for the sizing.

  • This is correct. If it's an instanced scene and there are shared resources, then modifying one modifies the other.

    You need to mark them as unique to allow individual editing. There is a button on the right for the resource (such as the collision shape) to "Make Unique" under an arrow.

This is correct. If it's an instanced scene and there are shared resources, then modifying one modifies the other.

You need to mark them as unique to allow individual editing. There is a button on the right for the resource (such as the collision shape) to "Make Unique" under an arrow.

Thank you @cybereality. You led me down the right path. I had to do a three step process to ensure that they were all separate. First add the scene, then right click on it and make it local. Next, drill down to the Collision shape and select it. Click on the tool icon towards the right of the property search bar, and select Make Sub-resource unique. After this, i was able to select my drop down to determine the collision shape size. Also, I know this isnt the most efficient method of making a card board game, but I'd like to make my scenes modular in case I'd like to move them to another project.

This seems like an okay way to do it, at least for a single screen type of game. There are ways to use inheritance for each card class but if you are talking about 10 or 20 cards there should be no issue with performance either way. However if you have like 100 cards or more maybe you could look into more optimized methods.

    cybereality So my thought process here was simply for board placement. having collision shapes to monitor where the mouse was and if a card was "picked up" if I hover over a matching area, the animation would kick in to move other placed cards to allow the one in hand.

    Also, don't forget the good old "Editable Children" tick box. Click this on and you can change elements in the scene without making a while new object. (like say a sprite or a collision shape)

    though to add onto what @cybereality said - instanced scenes share resources. You might consider doing a class for these objects instead to share with variables and functions and such, rather than an instance.

    Yes, I would probably make a base class with all the functionality. Then then subclass it with properties for size of collision, or the graphic or color or whatever.

    The advantage of this is that you still don't duplicate code (that can all be generic on the base class) and all the objects that are the same size use the same memory, so it will be more efficient.

    Though if you only have 5 or 10 objects, it's not a big hassle either way, but it will make your life a little easier in the long run for a full game.