Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Oct 02, 2016 at 08:01 AM by Fornoreason1000 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Fornoreason1000 · Oct 02, 2016 at 06:53 AM · arrayserializationnulleditor windowconstructor

Why do Constructors return null when used within EditorWindow

I'm writing a Popup-ytype window to be used for creating "Effects" for character skills an Items and this Bizzare behaviours starts happening. Its one thing to have Unity inbuilt class constructors return null (Like Avatar) but a custom class that I wrote that uses virtually a default constructor?

   public void AddEffect(int lastIndex)
         {
             effectIndex = lastIndex;
             //proof that my variable isn't being reassigned
             var effect = new Effect();
             Debug.Log(effect); //return null everytime
             //variable I'm trying to assign
             this.currentEffect = new Effect(); //also null

The strange thing is the first line works. effect index get correctly assigned, but anytime i call a constructor it returns null. Also all Unity-Inbuilt classes/structs such as Font or Vector3 work. . Here is my Effect class

  [System.Serializable]
     public class Effect : UnityEngine.Object
     {
         public int code = 0; //Deal Damage
         public int code2; //What formula
         public string id; //ID 
         public int intValue; //Element
         public int frame; //Apply effect during this frame of the animation
         public float floatValue; //variance
         public string stringValue;
         public bool boolValue; //is crititcal
       //Added for an insanity test, not actually needed
         public Effect() 
         {
             code = 0;
             code2 = 1;
             id = "id";
             intValue = 12;
             frame = 60;
             floatValue = 3.1f;
             stringValue = "hello";
             boolValue = false;
 
         }
         
 
     }
 }

and the AddEffect() is called from another Editor script called skill Editor, DrawBlankEffect() is called from OnGUI(), the idea is when the Effect editor is finished editing it fires a callback to skill editor that applies the changes in the Effects array.

 /// <summary>
         /// 
         /// Fucntions as an "Add" button
         /// </summary>
         void DrawBlankEffect()
         {
             EditorGUILayout.BeginHorizontal();
             GUILayoutOption[] myOptions = new GUILayoutOption[] { GUILayout.Width(60) };
             GUIStyle boxstyle = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).box;
 
             bool clicked = GUILayout.Button("", boxstyle, myOptions) || GUILayout.Button("", boxstyle, myOptions); ;
 
             if (clicked)
             {
                 Debug.Log("Blank Effect");
                 var window = EffectEditorWindow.Init();
                 window.AddEffect(2);
                 window.addEffectEvent += new EffectEditorWindow.AddEffectDel(AddNewEffect);
                
             }
 
             EditorGUILayout.EndHorizontal();
         }


I didn't think a null returning constructor was actually thing that can be done, let alone have it done automatically to my code. All code examples are with their own namespace, the two editor scripts in a respective Editor Namespace. All using statements are present.

can some please explain what exactly is happening here? Why does only Effect reutrn null in its constructor? if you need more information just post what you need in the comments

thanks in Advance

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by Fornoreason1000 · Oct 02, 2016 at 08:01 AM

there is infact a Fault with the Effects scripts.

it inherits from UnityEngine.Object. As @Bunny83 around 9 months ago.

you should not derive your own types from UnityEngine.Object. That class has a special meaning to Unity and is always linked to a native C++ counterpart. If you create an instance of your own UnityEngine.Object derived type it will become a fake-null-object.

so thats what happens when you have a "fake null object".

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

62 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Save a custom Class Array 0 Answers

[Solved] Array is empty after Scene change.. 1 Answer

Help with classes and object constructors 1 Answer

NullReferenceException with serialized array 0 Answers

Very slow performance when variable has serialize tag 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges