A problem (again) with group object variable

Hello. Sorry to disturb you again but it’s drinving me crazy!

I have different instances of an “door” object in-game. All these instances are in a group object “doors” and all these instances have a different object variable “name”. I would like to change the animation of one of the door only but no matter what i try all the doors get their animation changed at once… Any idea?
Basically how can i change the animation of one instance of the same object? :question: :cry:

You need an object variable that is different for each object in order to pick a specific object from a group.
Assuming the name of each object is different you can do something like

Condition

For each doors If text of variable name of doors = "metal"

Action

Change animation of doors

In this case you pick ALL the metal doors from the group doors.
However, in case you want to pick a specific instance of the metal doors, you need to have an additional variable that is different for each instance. For example, if you have an ID variable with a number and you do know which instance is which number could do something like:

Condition

For each doors If text of variable name of doors = "metal" If variable ID of doors = 10

Action

Change animation of doors

In this case you pick only that single instance of the door from the group doors that name is “metal” and ID is 10 assuming there is only one metal door with the ID value 10.
You need to add the ID values manually to each instance.

Off-topic: this is the case when it could be useful to pick the internal ID of an instance. Internally each instance has a unique ID that I believe I did submit a feature request for to be able to get id of instances using events and also in the editor so in similar cases we could just see in the editor what is the id of the selected instance and then we could refer to an instance by it id value using events…

So instead of

For each Is this true Is this true Is this true Then Do something to the instance

We could just

Pick instance by ID Then Do something to the instance.

Back to topic: However, in case you do collide or click the doors with the mouse, you can also pick the instances by simply checking which instance is involved in collision or been clicked and staff. You can also link the objects with variables in case you want to create switches that opens certain doors. To create a link add the same variable to the switch and the door instance, for example an ID variable that has the same value for the switch and the door you want to link and then

Condition

If player is in collision with switch If E key is pressed --For each doors ----If variable ID of door = Variable ID of switch

Action

Change animation of doors

Obviously, the ID value in this case need to be the same for the switch and door instance. And again, you need to set this value manually.

First of all thanks for your answer and for the “switch tips”. :smiley:
I already tried the way you explained but you answer made me realize i surelly messed somewhere with the difference between object variable value and object variable text…i’m not used to that feature… I will see tomorrow.

And maybe i didn’t understand you but how do you do that :
“in case you do collide or click the doors with the mouse, you can also pick the instances by simply checking which instance is involved in collision or been clicked”

off topic
I also think that an internal instance ID feature would be awesome

I meant GDevelop pick the instance for you that is involved

Condition

If player is in collision with door

Action

Change animation of door

It should work like that as long only one door is in collision with the player at the time.

Condition

Left mouse button is down Mouse is over door

Action

Change animation of door

Same it should pick the instance that meet the condition.

If multiple door objects meet the conditions, then you need to use the For each and additional conditions to find the single one you need.

And it would be also help with performance since you don’t need to check a bunch of conditions, you can just go and pick the instance straight away. In case you have lot of instances in your game For each can be a heavy task and may hit performance depends on what conditions you check For each instance.