Weird problem about executing Awake methods

Hi. When I run the app,Awake method is executed and go inside InitializePanelDictionary function but when it reaches SetPanelData function, it is not executed and instead other awakes are executed!!

  [System.Serializable]
    public class CPanelData
    {
        public CBasePanelView m_basePanel;
        public CBasePanelView m_parentBasePanel;
        public EPanelType m_panelType;
    }



  [SerializeField]
    private CPanelData[] m_panelData;
public void InitializePanelDictionary()
    {
        m_panelDictionary = new Dictionary<EPanelType, CBasePanelView>(4 * m_panelData.Length); // multiply by 4 to avoid more collision
        for (int i = 0; i < m_panelData.Length; i++)
        {
// m_panelData: it is an array
            CBasePanelView basePanel = m_panelData[i].m_basePanel;
            basePanel.SetPanelData(m_panelData[i].m_panelType, m_panelData[i].m_parentBasePanel.m_panelData);
           
            m_panelDictionary.Add(m_panelData[i].m_panelType, basePanel);
        }
    }
    // Use this for initialization
    protected override void Awake()
    {
        base.Awake();
        InitializePanelDictionary();
    }

The method would run all the way through unless you are getting an error?

NullReferenceException: Object reference not set to an instance of an object
CPanelManager.InitializePanelDictionary () (at Assets/Scripts/Manager/CPanelManager.cs:122)
CPanelManager.Awake () (at Assets/Scripts/Manager/CPanelManager.cs:131)

this line is 122
basePanel.SetPanelData(m_panelData.m_panelType, m_panelData*.m_parentBasePanel.m_panelData);*
I checked it basePanel is not null and is initialized correctly
I found and got it thx

Well, what about the other parts (the parameters) – are those not null? Something on that line must be, to give you that error. That’s also why you see other Awake methods being called, as that Awake throws an exception, doesn’t continue, and other scripts go on…

1 Like