Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Aldwin · Dec 21, 2013 at 04:43 PM · prefabserializationcustom editor

Variable modified with custom editor not saved when enter play mode, even with serialized attributes.

Hello!

I read a lot of forums and questions for this problem but I'm still unable to find out the solution.

I modify a variable on a prefab from a custom editor on anothe prefab. I used all the [System.Serializable] on my custom classes but the variable is still not saved when enter in play mode.

Here my code (I simplified it to keep only the essential informations) :

Custom editor script for Arena script :

 [CustomEditor(typeof(Arena))]
 public class ArenaEditor : Editor
 {
     public override void OnInspectorGUI()
     {
         DrawDefaultInspector();
 
         Arena arena = (Arena)target;
 
         if (GUILayout.Button("Action"))
         {
             foreach (Wave wave in arena.fight.waves)
             {
                 foreach (SpawnerData spawnerData in wave.spawnersData)
                 {
                         spawnerData.ID = 1;
                 }
             }
 
         if (GUI.changed)
         {
             EditorUtility.SetDirty(target);
         }
     }
 }

Arena script:

 [System.Serializable]
 public class Arena : MonoBehaviour
 {
     public Fight fight;
 }

Fight script :

 [System.Serializable]
 public class SpawnerData
 {
     public int ID;
 }
 
 [System.Serializable]
 public class Wave
 {
     public SpawnerData[] spawnersData;
 }
 
 [System.Serializable]
 public class Fight : MonoBehaviour
 {
     public Wave[] waves;
 }

The Arena script is on an Arena prefab instancied in the scene. This prefab references a Fight script on a Fight prefab instance in the scene too.

When I use the button on the Arena prefab instance, the ID is set to 1 on the Fight prefab. But when I enter "play" mode, the value is reset to 0.

I saw the ID value doesn't become "bold" when it changes to 1, I don't know if it means it won't be saved...

Thanks if you can bring any help to me !

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

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

Using a custom editor script with a prefab instance causes my variables to reset on Play 3 Answers

Serialization with custom editor, prefab not saving (again) 1 Answer

Is there a way to save a procedurally-generated mesh on the client machine? 1 Answer

Initializing a prefab from script in edit mode without breaking the connection 1 Answer

Custom editor, serialize and prefab issue 0 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