Realtime update of game objects in unity editor based on the values in the script

Hi,
I’m dealing with the following problem. I’m creating a simple game that is based on the maze. Maze nodes are prefabs. There are some basic node types that forms a maze – line, turn, T-junction, and cross. I’d like to improve a visual experience of the game with adding some extra appearance features to the maze components like torches, skulls, bones, or spider net. I do not wish to create extra prefabs (for example one completly without additions and others with them for each maze node type).

There is a solution to have an enum inside the script that is attached to the maze node prefab. The resulting appearance of the node is computed when the game starts in Awake() where adequate extra feature is instantiated and added to the node. The problem is that i won’t se the complete level appearance until the game is started.

The other possible solution is to add extra maze node features directly in the editor, but this break up the prefab.

Is there a solution such I will see the resulting maze node appearance directly in the editor before the game starts?

Thanks in advance.

You can implement a custom editor script for that. It needs to check when your enum value gets changed. As this happens, the individual objects need to be removed/replaced, … . It would work exactly as it does at runtime.
If you still only want to use one prefab (without lossing the connection), you may think to place the bones, skulls, … into an independant object hierarchy that is not stored in the editor. For that you may use the hideFlags of those game objects and set them to DontSave.

you could also try putting execute in edit mode at the top of the script. then in update put an if (!Application.isPlaying) Awake(); so it will call awake while in editor.

Thank you very much, handsomePATT. [ExecuteInEditMode] is exactly what I was looking for. This directive and some another tweaking do the job. I just have another question. I am targeting the game to the iOS. Every maze node has now attached MonoBehaviour script with some Update() method. I have this code at the first line of the method:

void Update() {
if (!Application.isEditor) return;

My question is – may the registration of update method in every node slow down the game even though there will be just simple if statement evaluated in every frame of the game? So far, it seems that the game runs smoothly but I’m expecting that i will add many new features to the game in future. Thanks

Yes, on the iPhone Update calls (which require reflection) are relatively expensive. If this leads to a serious performance drop, try replacing your Updates with coroutines.

If that is the only thing you have in Update, you may also place a #if UNITY_EDITOR around your Update to eliminate it as you make a build.