Simple example scene, a floor with a chair. At the edge of the floor is a trigger with the following simple script:
public GameObject prefab;
private void OnTriggerEnter(Collider other)
GameObject room= Instantiate(prefab);
//insert whatever code is needed to move the new room to a useful location
Everything (the floor, chair, and trigger) is parented under an empty gameobject, which is saved as a prefab, then the prefab is dragged to the trigger to fulfill the reference.
So in theory, you can walk forward forever, spawning new rooms. Heres the problem; if I knock over the chair in one room, it will be knocked over in all of the newly spawned ones. How do I break that connection?
Ermm, unless I’m forgetting something or whatever, that shouldn’t be happening. As long as you aren’t modifying that prefab at all, it will instantiate the prefab without saving any of the “settings” of other instances of the prefab. I’ve got an idea though. When you dragged in your “prefab” to this script’s
public GameObject prefab variable, you’re positive that it was actually a prefab, right? The behavior you describe makes it sound like you just dragged a prefab instance from the scene into that variable. With this, IT WILL create a copy of that object even with a chair fallen over.
Make sure that your prefab variable is populated with an actual prefab you grabbed from your Project window and not a scene object.
you dragged the instance (the room in the scene view) of the room to your script. you need to drag the prefab from the project window