- Home /
 
Custom editor, serialize and prefab issue
Hello, I am making a fairly simple custom editor, but I've stumbled across a problem. Whenever I click play after having edited a variable, the first frame of the game, the value reverts to it's prefab value. This only happens with prefabs.
My scripts are as follows.
EditorScript
 using UnityEngine;
     using System.Collections;
     using UnityEditor;
     
     [CustomEditor(typeof(PlayerManager))]
     [InitializeOnLoad]
     [System.Serializable]
     //[Serializable]
     [CanEditMultipleObjects]
     public class PlayerEditor : Editor 
     {
         SerializedProperty sphereAmount;
     
             SphereHandler sHandler;
     }
     void OnEnable()
         {
     
             sphereAmount = serializedObject.FindProperty("sphereAmt");
     
             sHandler = Selection.activeGameObject.GetComponent<SphereHandler>();
     }
     public override void OnInspectorGUI()
         {
             serializedObject.Update();
     
             myTarget = (PlayerManager)target;
     EditorGUILayout.IntSlider (sphereAmount, 0, 100, new GUIContent ("Sphere Amount"));
                 
             sHandler.sphereAmt = myTarget.sphereAmt;
             EditorUtility.SetDirty(myTarget);
     serializedObject.ApplyModifiedProperties ();
     }
     }
 
               The script i override(basically a shell to modify several other scripts)
 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class PlayerManager : MonoBehaviour {
 
     public int sphereAmt = 8;
 }
 
               and the script which i modify SphereHandler using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Linq; [System.Serializable] public class SphereHandler : MonoBehaviour {
     public int sphereAmt = 5;
 void Start()
 {
     Debug.Log(sphereAmt);
 }
 
               The sphere amt. is always the same value the first 1-2 frames and then changes to the one i set it to in the inspector, but i need to use it on start so it's not ideal. This only happens when the object is a prefab
I hope someone can help :) Thanks in advance!
Your answer