[Solved] Create object from a group once


I have 8 objects in a group.
What is the simplest way to randomly create 3 objects from a group in different positions, but keeping in mind that each object can only be created 1 time.

:wave: Hi and welcome here :slight_smile:
I think the simplest would be to place the 8 objects on the scene (out of sight), then do:
Repeat three times: variable moved of Group is False, pick a random Group, move it, change variable moved of Group to True.

1 Like

Hey, thank you for the welcome.

I’ve been trying to do it with my own all day today, but can’t get it to work.
I could use your solution, but in the future there will be more object in the group and I need to delete those objects and run the function again when needed.

Every time the object is created I place the object name into variable and add + 1 to counter variable and start creating another object. If that object has the same name as the first one, reset all variables until variables have different names. Repeat until all 3 variables have different names and counter is 3

I’m totally aware I complicated the situation but I couldn’t think of any simpler way.

While loop is kind of the hardest way to go. But if you like paracetamol, have fun with it. :grin:

Haha it is certainly giving me a headache. I guess I will do more trial and error for now.

Just of the curiosity, what way would you suggest to go for? I assume I need to have some kind of a loop.

Sorry for the spam replies :no_mouth:

I’ve been trying to use your solution in the first post where I place the objects outside the screen and change their position.

Doing this only 2 out of 3 required objects actually change their position and variables from false to true.

Nevermind, I had another condition that didn’t let the third object move in place on time. Thanks for this solution.

I’m not sure if you already changed this but you need to reverse your conditions. Think of them as a filter. You need to filter or only pick the objects with the false boolean first and then pick a random one of those.

Hmmm, I see what you mean but I’m not sure how to do it.

Sometimes it moves 2 objects, sometimes 3.

Just swap their places but keep the conditions inside of the repeat event. You need to remove the instances from consideration as they get randomly picked and their boolean variable is set to true.

   Boolean = false
   Pick random

The first time through the repeat loop, all the objects are “picked” because their boolean variables are false, it chooses a random object among those 3 and you set the boolean of it to true, the next time there are only 2 to choose from and the the 3rd loop, there’s only 1 left so it picks that one.

Awesome I got it working, thank you.

1 Like