- Home /
Instantiated objects not appearing in scene or game view
For a project I've been working on, I have been instantiating randomly chosen prefabs from a list to a clone array on the press of a button. And when that same button is pressed again, it cleans out the clone array and instantiates more random prefabs all over again.
For the most part it works flawlessly, however, after pressing the randomize button exactly 30 times, the objects do not appear in either the scene view or game view. Said objects are not deactivated nor is their mesh data missing in the inspector. Their mesh renderers are also still active. They show up in the hierarchy with the correct names, and if I select them they look like empty game objects in the scene view, with their origin point being at the correct spot.
I have another script that functionally does the same thing, and it has no problems after 30 attempts, so this is boggling my mind.
Any ideas?
Answer by logicandchaos · Feb 04, 2021 at 01:40 PM
What position are the objects supposed to be? Are they in the hierarchy?
The objects are meant to spawn at the location of a designated empty object which also acts as their parent in the hierarchy. The objects appear in the hierarchy in the correct spot, and when I select them it shows the correct origin point, where they are meant to spawn, but no mesh appears.
Answer by ActiveMars91 · Feb 04, 2021 at 02:09 PM
Also, how do you instantuate the objects with a buton press? is the instantiation taking place in any type of loop?
The instantiation is just a simple function that spawns all of the objects on the same location, as I've made all of the prefabs modular to fit together properly. It randomly chooses which objects it wants to spawn, then puts them there, and the button simply calls that function.
The only loop that exists (other than pressing the button over and over) would be with choosing the parent empty's location, which is done through casting rays in a small area at other objects until they either hit or somehow miss 100 times in a row.