Preview script generated gameobject in scene view when not in play mode

Viewed 37

I create an empty GameObject and attaching some scripts for generating the mesh and texture with several properties. How could I preview the the script result in Scene View when it's not in play mode? It's show nothing now.

And I also want the preview changed when I change the property value in Inspector. Do I need to loop read the property value every second? This seems not a good idea.

So what is the general solution for my situation? I guess there must be a commonly used way for a generated GameObject.

Here is the example, I write a script to generate Cube mesh with x, y, z size. Now there are nothing show in the scene view, and when I change x, y, z value in inspector, nothing happened except I click play. I want to see the preview in Scene View just like I right click and created a Cube GameObject provided by Unity.

This is my Cube's inspector:

enter image description here

1 Answers

By default, MonoBehaviours are only executed in Play Mode. By adding the ExecuteInEditMode attribute, any instance of the MonoBehaviour will have its callback functions executed while the Editor is in Edit Mode too. After that, you are able to check a value change in the Update()-Method.

Related