Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 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 sauerkraut · May 28 at 08:49 PM · prefabeditor-scriptingsave scene

Code-generated changes to prefab override properties not persisting

Hi - I have a within and across level player transition system which uses a "Transition" prefab that has a GHTransitionController component with a unique ID. When events happen in the game, the game can reposition the player at any one of these Transition points. The unique transition ID together with the Scene Name works well.

The problem comes when I try to automatically assign GUIDs to the TransitionID of new Transition points in the editor.

I have tried using OnSceneSaving to generate the GUIDs whenever the scene is saved, which looks like it is working well (ie. I can see in the editor that the TransitionID field of any GHTransitionController which were previously blank get GUIDs whenever I Ctrl-S.

However the change doesn't seem to persist. As soon as I load another scene and reload the original, or enter Play mode, the value is reset to the original "blank".

Any thoughts? A stripped back version of my editor code is below.

 using UnityEngine;
 using System.Collections;
 using UnityEditor.SceneManagement;
 using UnityEngine.SceneManagement;
 using System;
 #if UNITY_EDITOR
 using UnityEditor;
 
 namespace Assets.GunheadEditors
 {
     [UnityEditor.InitializeOnLoad]
     static class OnSaveSceneLogic
     {
         static OnSaveSceneLogic()
         {
             UnityEditor.SceneManagement.EditorSceneManager.sceneSaving += OnSceneSaving;
         }
 
         private static void OnSceneSaving(Scene scene, string path)
         {
 
             foreach (GHTransitionController tc in GameObject.FindObjectsOfType<GHTransitionController>())
             {
 
                 if (tc.TransitionID == "" || tc.TransitionID == null)
                 {
                     tc.TransitionID = Guid.NewGuid().ToString();
                     EditorSceneManager.MarkSceneDirty(scene);
                 }
             }
          }
     }
 }
 #endif


Further analysis - I have found that after doing a Ctrl-S and having the TransitionID visibly generated in the editor if I then ALSO manually modify any other property of the same component, the generated TransitionID change (together with the "other" change) persists. Its like Unity has a dirty flag not just on the scene, but also on objects?

I have now also tried creating a custom editor with a button which generates the ID with exactly the same behaviour. Very strange.

When I completely unpack the prefab instance, the problem goes away, so I know it is a prefab overriding issue.

However this doesn't help me as I need prefabs for this as there are loads of other components required.

The strange thing is that when I click my custom editor button, I can see the captions next to the TransitionID going BOLD, indicating that the property has been overridden when it populates. When I then go to Game mode, the bold disappears, the TransitionID is blanked, and when I stop the game the TransitionID caption goes bold again, but the value doesn't return.

Is this a bug? I am on 2021.3.2f1.

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

190 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 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 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

How to set a prefab SpriteRenderer.sprite using script in editor? 1 Answer

Could not load copied asset via AssetDatabase.LoadAssetAtPath 4 Answers

What is the prefab is not valid since it has no root game object error? 1 Answer

If I make changes to a prefab in the Project tab, do I have to save the scene, too? 1 Answer

Display changes in the editor made to a prefab 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