Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity 4.5 EditorWindow "Can't add script behaviour . The script needs to derive from MonoBehaviour!"

Discussion in 'Scripting' started by Peter Gartside, Jun 13, 2014.

  1. Peter Gartside

    Peter Gartside

    Joined:
    Oct 23, 2012
    Posts:
    9
    Hi All

    This has just started happening to me when i upgraded to 4.5.0 and it happens in 4.5.1.
    The problem is I create an GameObject and Add a camera component to it and then try and add my script as a component when i enable the edit window

    Code (CSharp):
    1.         GameObject obj = new GameObject("SCW My Camera");
    2.         obj.transform.position = new Vector3(100000,100000,100000);
    3.         obj.AddComponent<Camera>();
    4.         obj.AddComponent<SpriteCreaterCamera>();
    And my SpriteCreateCamera is

    Code (CSharp):
    1. public class SpriteCreaterCamera : MonoBehaviour
    2. {
    3. }
    This worked in 4.3.4 but in 4.5.0 or 4.5.1 it always fails.

    Anyone having the same problem?

    Cheers
    Pete
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Did everything compile correctly? Did you try to reimport a script, such that all scripts are recompiled? Is the SpriteCreaterCamera in an editor folder? Do you have more than one script names SpriteCreaterCamera? Did you try to reproduce it in a new project?
     
  3. Peter Gartside

    Peter Gartside

    Joined:
    Oct 23, 2012
    Posts:
    9
    It all compiled ok.

    From a fresh install of unity i works but if i edit the EditWindow class it fails after that.

    Yes

    No

    No I haven't tried this yet.
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    SpriteCreaterCamera is not allowed to be in an editor folder!
     
  5. Peter Gartside

    Peter Gartside

    Joined:
    Oct 23, 2012
    Posts:
    9
    Cheers all working now :)
     
  6. Gingerman007

    Gingerman007

    Joined:
    Aug 26, 2015
    Posts:
    1
    How?
     
  7. TamaHobbit

    TamaHobbit

    Joined:
    May 18, 2014
    Posts:
    10
    The error message is still wrong though; it should say: The script must derive from monobehaviour AND not be inside a folder named "Editor"

    Is Unity going to fix this?
     
  8. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    It's pretty clear from the documentation
    http://docs.unity3d.com/Manual/SpecialFolders.html