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 /
avatar image
0
Question by gregmax17 · Aug 11, 2011 at 05:52 PM · editorprefabcustom

Saving its values through custom Editor

This is my first time trying to create an Editor script to edit an prefab properties and values through the Editor. I am having issues saving the prefabs array. I am able to add/remove objects to the array, but once I click on the PLAY button, the array is destroyed.

This is my Editor script:

#pragma strict

@CustomEditor(MyController)

class MyControllerEditor extends Editor { function OnInspectorGUI() { var my : MyController = target as MyController;

     GUILayout.BeginHorizontal("Button");
         if ( GUILayout.Button("Add Object to Array") )
         {
             my.someArray.Push(new Object());
         }
         if ( GUILayout.Button("Remove Object from Array") )
         {
             my.someArray.RemoveAt(0);
         }
         if ( GUILayout.Button("Remove All from Array") )
         {
             my.someArray = new Array();
         }
     GUILayout.EndHorizontal();

     my.randomVariable = EditorGUILayout.IntField("Hello", my.randomVariable);
 }

}

This script is attached to the prefab:

#pragma strict

var someArray : Array = new Array(); var randomVariable : Int = 0;

class someObject() { var prop1 : String = "a value"; var prop10 : String = "a longer value"; }

Am I doing this the proper way? How come the array is being destroyed when I PLAY and STOP the game in the Preview? Side note: setting the 'randomVariable' in the Editor works fine.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Waz · Aug 11, 2011 at 10:40 PM

I'm not certain, but I suspect the problem is Unity not serializing an Array, since that won't work in the default inspector either. If you use a normal built-in array, it should work:

 my.someArray += [new Object()];
 

etc.

 var someArray = new Object[0];
Comment
Add comment · Show 2 · 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
avatar image Owen-Reynolds · Aug 12, 2011 at 02:40 PM 0
Share

Yah -- first make sure everything you need shows up in the normal Inspector. A trick for testing is to also call DrawDefaultInspector in your CustomEditor -- changes from custom should be immediately reflected.

avatar image gregmax17 · Aug 16, 2011 at 11:45 AM 0
Share

Awesome! The DrawDefaultInspector worked like a debug tool for me. And the my.someArray += [new Object()]; worked like a charm!

Thanks again!

avatar image
0

Answer by karl_ · Aug 11, 2011 at 06:05 PM

I think you're looking for EditorUtility.SetDirty()

http://unity3d.com/support/documentation/ScriptReference/EditorUtility.SetDirty.html

Comment
Add comment · Show 2 · 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
avatar image gregmax17 · Aug 11, 2011 at 06:08 PM 0
Share

I have looked at that and have tried this but it doesn't work:

EdtiorUtility.SetDirty(target);

Am I using incorrectly?

avatar image Waz · Aug 11, 2011 at 10:42 PM 0
Share

SetDirty just tags that an asset needs saving. It is not used for non-prefab changes like this.

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Extending "GameObject/Create Other" with own prefab 1 Answer

Custom Data structs & Inspector 1 Answer

How Mark Prefab Dirty? 1 Answer

Unity editor and inspector header 0 Answers

How does Unity retain UnityEngine.Object references? 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