How to give dozens of items the same name for collision code

A student has about 80 trees in a scene. When they collide with any of them, they want to restart the scene. How do we easily code this, so that they don’t have to add a line of code for each of the 80 trees? Thanks!

1 Like

Hi @Kelly_Nickell here are two options to solve this:
For both options all tree’s must grouped together, and this group must be eneabled for coBlocks,

Then for option one, I turn this group into a list by looping through each of the indexes of the group, then adding an event for the player, that if it collides with “another item”, and “another item” is in the tree list, then: restart the scene.

For option two, i loop through each of the tree’s in the group and add an event for each tree that if they collide with the player they must restart the scene; However in this case it would make for 80 seperate events the computer must keep track of which can be quite expensive to run preformance wise, so I’d advice against using this one for that many objects.

Below the coSpace with the code, hope this helps!

1 Like

There’s an easy way:

  1. Give every tree the same name, e.g. “Tree”
  2. Use the advanced collision event to assign the collided item to a variable (enable Advanced CoBlocks under Settings first)
  3. Check the name of the collided item to see if it equals, or contains, “Tree” (using an IF-THEN control block)
  4. If it is, restart the scene

Feel free to remix the following example:

Hope this helps! Let me know if you have any further questions. If this post solves your problem, please mark it as the Solution.

Many thanks,


Also if you’re using @techleapnz 's method an easy way to keep the name the same is using the hotkeys ctrl+c, ctrl+v to copy and paste the object; This will keep the name identical, instead of using the right-click duplicate method which will add a number behind it.

1 Like

Oooo, I did not know that - thanks for sharing, @Luc !