Quantcast
Channel: Latest Questions by Xelnath
Viewing all articles
Browse latest Browse all 24

How do I correctly edit an object in another scene?

$
0
0
I am using additive scenes, then have an editor function to modify a property an another object inside a different scene. However, it's not saving the change when I hit play!! Here's the code: var units = GameObject.FindObjectsOfType(); foreach ( var unit in units ) { if ( unit.IsFirstPickUnit == true ) { unit.IsFirstPickUnit = false; if ( !Application.isPlaying ) EditorSceneManager.MarkSceneDirty( unit.gameObject.scene ); } } But it doesn't work! The scene is correctly marked dirty, but the unit's flag is NOT changed. So I tried this next: var units = GameObject.FindObjectsOfType(); foreach ( var unit in units ) { if ( unit.IsFirstPickUnit == true ) { unit.IsFirstPickUnit = false; var serializedObject = new UnityEditor.SerializedObject(unit); var prop = serializedObject.FindProperty( "IsFirstPickUnit" ); prop.boolValue = false; serializedObject.ApplyModifiedProperties(); serializedObject.SetIsDifferentCacheDirty(); serializedObject.Update(); if ( !Application.isPlaying ) EditorSceneManager.MarkSceneDirty( unit.gameObject.scene ); } } That didn't work either. What am I doing wrong? It keeps leaving the flag as "true" on any object modified in another scene. (even if I hit save)

Viewing all articles
Browse latest Browse all 24

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>