Wait till instantiated is done

Well the problem is that once an object is being instantiated , it remains null for an undefined time , so any calls to it’s interface produce an exception.I wonder if there any right way to handle situations like this.

Thanks!

You should have access to the GameObject in the next line after instantiating. Is there something funky you’re doing in Awake or Start?

GameObject go = Instantiate(someOtherGameObject, someTransform.position, someTransform.rotation);
go.GetComponent<SomeScriptName>().someProperty = someValue;

Can you perhaps add more value to your question with some code?

Well your problem can easily be solved in two ways:

  • Use Awake instead of Start to initialize references to objects on your own object.
  • Use a property to initialize the reference.

The first one is the easiest fix in your case. Just do your GetComponent in Awake.

The second one is more reliable:

public class Button : MonoBehaviour
{
    private ButtonView m_ButtonView = null;
    protected ButtonView buttonView
    {
        get 
        {
            if (m_ButtonView == null)
                m_ButtonView = GetComponent<ButtonView>();
            return m_ButtonView;
        }
    }

    public void SetButtonToState( ButtonView.States newState )
    {
        buttonView.UpdateState(newState);
    }
}