Quantcast
Channel: Latest Questions by Tanoshimi2000
Viewing all articles
Browse latest Browse all 91

Prefab modified by script in Editor loses changes when IsPlaying

$
0
0
Looked all over, no solution. This is simple. I drag and drop a prefab onto my scene. It's built in script randomly resizes it. That works fine. But when I run it, the prefab gets resized again. I control whether or not to run the resize routine with a public boolean, and a private boolean. Basically, when the user checks the box to make it Unique, it runs the resize and sets the private boolean to show that it's already been done, so that it doesn't run in every iteration of Update. Works great in Editor. I can resize and restore to my heart's content. But when I run it, apparently the value for the private bool is being lost because it's running the resize routine. And when I stop the run, it runs it again. I need this to resize once, in the editor, on command, and then remember those settings/scale when it's run and when the run is stopped. I'm not using a custom editor, but I've tried SetDirty, and Serialization. Nothing is working. Here is most of the code, the part that controls when the resize (Randomize) function is run. #if UNITY_EDITOR using UnityEngine; using UnityEngine.UI; using UnityEditor; using System.Collections; [ExecuteInEditMode] public class AlienEditor : MonoBehaviour { public bool MakeUnique; private bool IsUnique; // To determine if we need to change it. // Use this for initialization void Start () { // Not doing anything in here! } // Update is called once per frame void Update () { // Don't do this when the game is running, only in the editor if (!Application.isPlaying) { // Make it unique if ((MakeUnique) && !(IsUnique)) { Debug.Log("Time to Make Unique!"); Randomize(gameObject.transform); IsUnique = true; EditorUtility.SetDirty(gameObject); } // Make it standard if (!(MakeUnique) && (IsUnique)) { Debug.Log("Time to Load the Prefab!"); Reset(); IsUnique = false; } }// Not Playing } } #endif

Viewing all articles
Browse latest Browse all 91

Latest Images

Trending Articles



Latest Images