- Home /
Question by
james072898 · Oct 10, 2020 at 10:14 AM ·
gameobjectprefaboverride
Prefab doesn't override variables
Hi.
I have a panel that popup when clickng an object, so i have this code on the object
using UnityEngine;
using UnityEngine.UI;
public class YardScript : MonoBehaviour
{
public GameObject yardPanel;
void OnMouseDown()
{
yardPanel.SetActive(true);
}
}
But when i set on the inspector the gameObject that contains the panel and click on override doesn't work, every time i instantiate a new clone of it, have to mannualy assign the panel. I tried to assign it manually from script like this:
using UnityEngine;
using UnityEngine.UI;
public class YardScript : MonoBehaviour
{
public GameObject yardPanel;
void Start()
{
yardPanel = GameObject.Find("Yard Panel");
}
void OnMouseDown()
{
yardPanel.SetActive(true);
}
}
But the variable still being "None (Game Object)". Any idea?
Comment
Answer by YoungDeveloper · Oct 10, 2020 at 10:18 AM
yardPanel reference is not in the the scope of prefab itself but somewhere in the scene, right? That reference gets lost, if you have setup it that way.