Randomized objects on object (Prefab?)

Updated on December 21, 2018 in  [R] Tutorials
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on December 20, 2018

I having idea but I don’t have any idea how to make it coming true.
The idea is that let us say that I have a table (3d model) that I would like to drag into scene. But while adding it into the scene the table will get randomized objects on it.
Lets say I have made these 3D Models as shown on the image (https://imgur.com/sVfcEXp), Table, 2x Screens, 2x Keyboards and 2x Flowers.
Every time I drag the table (prefab?) into the scene then i would like to that the Screen, keyboard and flower randomizes on the table so it looks different each time and saves the object on scene as it becomes. I think it would be better to do that way with different separated objects than creating all the variation objects.


  • Liked by
0 on December 21, 2018

I think unity has some editor function that you can use to only do something when a prefab is added in the editor, but I don’t know editor scripting too too well.

You could, however, still just make a RandomizeTableTop function, that will clear the table, and randomly pick prefabs from a list, then place them in random positions, with random y-rotations on the table. Once you have that, if you add [ContexMenu(“Randomize Table”)] with the ‘[]‘ above the function name, you can just right click the script on the table you want in the editor, and there should be a “Randomize Table” option. click that, and you can keep randomizing things until you like it.


Unity documentation on ContexMenu here

  • Liked by