draw own parameterized object in editor mode (best - usual way for this)

As I read on the Internet, this is a very common question, but I did not find an unambiguous answer to it.

I am making a parameterized object and I want to be able to place it in the editor on the stage, for this I need to at least designate it.

I read that the call to OnSceneGUI for this purpose, but it only works when gizmos is enabled. Is this the typical way to represent objects in an editor? Is it possible to do this in general without gizmos,

thanks

All the systems I’ve seen that use parameterised objects tend to just generate a standard Unity mesh which will be shown in the scene window, is that what you mean? Whenever you change a parameter the mesh gets regenerated so the editor display gets updated.

1 Like

Thank you very much for your answer!

Yes, I am generating a standart mesh based on parameters. It was not displayed in the editor in any way, only when the game was running. I added [ExecuteInEditMode] and the generated mesh was displayed in the editor. When changing the general properties, Rotate, Scale, Transform, as I understand it, inherited from Monobehavior, the changes to the grid are displayed in the editor. When I change my properties, the changes in the editor are not displayed.

Only when I run the script with new parameters, the object is drawn correctly and after stopping the script, in the editor the new parameters are applied to it.

This is without a OnSceneGUI call. When I adding a OnSceneGUI to the custom editor, the parameters are applied to the object, but only when gizmos is enabled. The standard parameters apply without gizmos.

I’m not sure I could help you more with that as it’s not something I know a lot about. It might be an idea to search google for “onscenegui github procedural” and you can see some examples of other people doing a similar thing. Perhaps you can get some ideas from their code? The first search result was the code for Unity’s tree generator that looked interesting: UnityCsReference/Modules/TreeEditor/TreeEditor.cs at master · Unity-Technologies/UnityCsReference · GitHub

Thank you very much for your answer and for the link to the source!

I analyzed the situation and I think that the reason is placed not inside OnSceneGUI, but in other procedures, that initialize the Editor, for example.

I guess they tell to Editor when to call OnSceneGUI (with or without gizmos). Or another option - OnSceneGUI is called only for active gizmos, and another procedure, for example OnGUI - without them (I have not studied this yet).

In any case, I will carefully study the code that you sent, not only OnSceneGUI, but also other functions.

many thanks for your help

1 Like

If you don’t want to create a custom inspector for your component you can use the OnValidate method to update / recreate your mesh. Be careful when recreating the mesh as Meshes need to be destroyed when they are no longer in use or they stick around in memory. Depending on the features of your procedural object you have more control with a custom inspector so you may react differently depending on what values have been changed. This could avoid unnecessary updates.