- Home /
Prefab doesn't hold prefab of itself, Instead just copies itself on Instantiate()
An object named BuildingParent has a script called BuildingParentScript. That script should hold the prefab GameObject BuildingParent (not a copy of itself but it's own prefab). And when I assign it in the Inspector it seems to work. But if I leave and re enter the prefab editor in seems to set the GameObject to itself instead of its prefab. So when I instantiate it, it makes a copy of itself, that copies all the children. This object can hold up to 500 children, so just deleting them seems bad for performance. Any ideas?
Answer by Pokedlg3 · Dec 22, 2020 at 10:54 PM
try adding this to your script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BuildingParentScript : MonoBehaviour
{
public GameObject newParentGO; // place the prefab building _parent here
public GameObject prefabReserve; // place the prefab building _parent here
void Update()
{
if(newParentGO != null)
{
newParentGO = prefabReserve;
}
}
}
I did the test and it worked
(Don't change the script, just add)
Your answer
Follow this Question
Related Questions
How do I instantiate certain objects to appear in a specific spot? 3 Answers
Problem with prefab parent and children objects that need to be instantiated multiple times. 1 Answer
i want to assign different colors to rows or different colors to the brick? 0 Answers