- Home /
Script on nested prefab Loses referance to parent prefab when instantiated
I have a prefab that is just a cube with "spawner" prefab off 3 edges, intended to fill a 2d plane between generated boundaries
On the spawners are scripts (one on each) that check for collisions and then instantiate a new copy of the cube
The problem comes after that first iteration.. some, not all, of the new spawners' scripts are lacking the reference to the cube prefab
They are public gameobjects that I dragged into the original spawner prefab, any attempt at tinkering so far has led to total reference loss (ie even the original seed prefab that I drag in to the scene is also missing references)
My code is simplistic so I can't see how it is interfering.. but here it is anyway
public class RoomSideBuilder : MonoBehaviour
{
public GameObject RoomUnit; // missing Reference, prefab has gameobj dragged in inspector
private float view = 160f;
private Transform t;
private Transform player;
void Start()
{
t = this.transform;
player = GameObject.FindGameObjectWithTag("Player").transform;
}
void Update()
{
Invoke("spawnNext", 1f);
}
private void spawnNext() {
if (PlayerDistance() < view * 0.8f)
{
Instantiate(RoomUnit, transform.position, transform.rotation, transform.parent);
Destroy(this.gameObject);
}
}
private float PlayerDistance()
{
return Vector3.Distance(t.position, player.position);
}
void OnTriggerEnter(Collider col)
{
if (this)
{
Destroy(this.gameObject);
}
}
}
I searched here before posting could not find any one with a similar issue, This is in 2018.3.3f1 Thanks for any help