• 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 /
avatar image
0
Question by sonny-ad · May 31, 2016 at 08:31 AM · editoreditor-scriptingeditorwindow

How to make my scene object reference survive the button play

Hi,

I did the tour of Google and Unity resources, I just can't seem to find an answer to my problem.

Basically I want use an EditorWindow to generate and manipulate some graphs tree that are then evaluated during the game. I generate those trees in the scene directly I may sometimes save them separately into a prefab but most of the time I just keep them into the scenes.

My drama as a lot of people had starts when I click play. The evaluation of the tree happens correctly but the visual of the tree I had in my custom editor window just vanished because it loses the reference to the scene object. So if I want to have this visual I need to redo the link manually on play time which is annoying.

Here is a sample to illustrate the same issue I basically have:

 [System.Serializable]
 public class Data : MonoBehaviour
 {
     public int difficulty = 0;
     public string description;
 }
 
 public class MyWindow : EditorWindow 
 {
     [SerializeField] // To be sure it is serialized
     public Data data;
 
     // Add menu named "My Window" to the Window menu
     [MenuItem ("Window/My Window")]
     static void Init () 
     {
         // Get existing open window or if none, make a new one:
         MyWindow window = (MyWindow)EditorWindow.GetWindow (typeof (MyWindow));
         window.Show();
     }
 
     void OnEnable()
     {
         hideFlags = HideFlags.HideAndDontSave; // Tried that
         EditorUtility.SetDirty(data); // that too
     }
 
     void OnGUI () 
     {
         data = (Data)EditorGUILayout.ObjectField(data, typeof(Data), true);
     }
 }

And here is my scene, where GameObject have Data attached to it and GameObject (1). alt text

Whichever the one I use, the ObjectField keeps getting reset on play. While if I use the prefab of GameObject in the project panel it doesn't. But it isn't the prefab that will be running in my scene and that I want to debug. It's the real instance in the scene...

Am I trying to do something that cannot be done?

Thanks.

scene.jpg (11.3 kB)
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

· Add your reply
  • Sort: 
avatar image
0

Answer by sonny-ad · Jun 02, 2016 at 03:09 AM

Been able to fix that issue with the solution given by @dkozar here

http://forum.unity3d.com/threads/editorwindow-loses-reference-of-scriptableobject-on-play-mode.107831/#post-1077162

\o/

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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

66 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 avatar image avatar image avatar image avatar image

Related Questions

Custom Editor Textarea cursor position 0 Answers

Is it possible to get Unity to compile specific scripts even if it can't compile the entire project because of errors. 1 Answer

How to Have a ReoderableList in a Custom Editor Window 1 Answer

My EditorWindow won't display properly, even when commented out. 0 Answers

Do Unity Editor GUI Utilities (Handles.DrawLine & EditorGUI.DrawRect) have limitations? 2 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