Hello,
Let’s say that we have a prefab X and it has a script that has a reference called “prefab” to the prefab X, in other words it points to itself. I created the GameObject, attached my script on it, created a prefab, dragged the GameObject to it then selected the prefab and then dragged it to the reference “prefab” in the script.
My problem is when I drag the prefab into the scene the reference “prefab” refers to the created instance not the prefab X itself.
I understand that by doing the steps I did Unity thought that I want a reference in a GameObject referring to itself not to the actual prefab.
I tried the following to prevent instances of the prefab to set the value of “prefab” but it didn’t work:
GameObject prefab;
public GameObject Prefab
{
set
{
PrefabType objectType = PrefabUtility.GetPrefabType(gameObject);
if (objectType == PrefabType.Prefab)
prefab= value;
}
get
{
return prefab;
}
}
When I did that “prefab” became null, I thought that it will keep its value when it was still a prefab but apparently when an instance is created from prefab it’s a new created GameObject with the same components then its values are copied from the prefab.
Any solution for that doesn’t use Resources.Load()?