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

Remove EditorWindow Warning

Discussion in 'Scripting' started by NightsWatch, Jan 15, 2015.

  1. NightsWatch

    NightsWatch

    Joined:
    Oct 4, 2014
    Posts:
    4
    I want to extend the functionality of unity editor, so I just follow the rules of the documentation:
    Code (CSharp):
    1. public class HelloWorldWindow : EditorWindow
    2. {
    3.     string    myString = "Hello World";
    4.     bool    groupEnabled;
    5.     bool    myBool = true;
    6.     float    myFloat = 1.23f;
    7.  
    8.     [MenuItem ("Window/HelloWorld")]
    9.  
    10.     static void Init()
    11.     {
    12.         HelloWorldWindow window = (HelloWorldWindow)EditorWindow.GetWindow(typeof(HelloWorldWindow));
    13.     }
    14.  
    15.     void OnGUI()
    16.     {
    17.         ...
    18.     }
    19. }
    After editing this C# class, I got my new class file compiled, yet I got a warning from the compiler:
    "warning CS0219: The variable `window' is assigned but its value is never used"

    So is there anybody know how to get rid of this warning?

    Since I'm new to C# (I used to use C++), this piece of code seems magic to me, because I can see the variable "window" be used nowhere, could anybody please explain how this window guy works behind the scene?
     
  2. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
    Code (CSharp):
    1.     static void Init()
    2.     {
    3.         HelloWorldWindow window = (HelloWorldWindow)EditorWindow.GetWindow(typeof(HelloWorldWindow));
    4.     }
    Right there
     
  3. NightsWatch

    NightsWatch

    Joined:
    Oct 4, 2014
    Posts:
    4
    Thanks, Nubz. I figured out that I can replace that line of code to
    Code (CSharp):
    1. EditorWindow.GetWindow(typeof(HelloWorldWindow));
    So actually Unity3D does not use the variable "window" that I declared in Init() method.