Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

New class not getting MonoBehaviour calls

Discussion in 'Scripting' started by guslindell2, Jan 15, 2020.

  1. guslindell2

    guslindell2

    Joined:
    Mar 4, 2018
    Posts:
    1
    My script has a second class in it (that inherits from MonoBehaviour) and I need to use methods like OnGUI with it. However, the MonoBehaviour functions don't get called; the constructor runs, but Start and OnGUI don't.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,517
    Put each MonoBehavior into its own file named the same as the MonoBehavior.

    Also, you cannot use
    new
    to create MonoBehaviors. Only use
    .AddComponent<>()
    from a valid
    GameObject
    .