I need one specific script to run continuously in edit mode for a period of time, without having to change things on the scene for it to Update.
Would runInEditMode be what I need for that?
And if so, how am I supposed to use it?
What I’ve tried so far is setting it to true … using [ExecuteInEditMode] and placing “this.runInEditMode = true” in Update()… and also setting it true from an EditorScript just in case, so yeah, trying random things at this point.
I’ve debugged “this.runInEditMode” and confirmed it’s true. Yet still ONLY updates when I perform changes on scene.
For my first attempt I created the following script and attached it to a cube. When the cube is selected, or any changes are made to the scene, it is updating. There is very little information on this available so I’m guessing it’ll be trial and error.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class Foo : MonoBehaviour {
// Use this for initialization
void Start () {
this.runInEditMode = true;
}
// Update is called once per frame
void Update () {
this.transform.Rotate(new Vector3(1.0f, 0.0f, 0.0f));
}
}
Hey! And this is working? Very interesting!! Maybe I’m doing something too weird, I can’t manage to update continuously. But it’s good to know that’s how it should work, Thank you!!
For my second attempt I abandoned the boolean. It’s constantly updating, but it’s constantly spewing an error too.
Random Test Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpinSprite : MonoBehaviour {
void Update () {
transform.Rotate(new Vector3(0.0f, 0.0f, 1.0f));
}
}
Editor Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class ForceUpdate : EditorWindow {
[MenuItem("Window/Force Update Window")]
private static void Init()
{
ForceUpdate window = (ForceUpdate)EditorWindow.GetWindow<ForceUpdate>();
window.position = new Rect(0, 0, 25, 25);
window.Show();
}
private void Update()
{
foreach (MonoBehaviour mb in FindObjectsOfType<MonoBehaviour>())
{
mb.SendMessage("Update");
}
}
}
Here is the error message. Repeated every frame from the looks of it.
For the record all testing was done under 2017.1f3.