- Home /
Custom Inspector with Procedural Mesh Preview?
EDIT: My question, in short, is: Is it appropriate to create procedural Meshes (and GameObjects) in a custom inspector for visualizing data in the scene view while the game isn't running? And if that's a workable approach, how do you manage the lifespan of these generated objects so they don't linger and clutter up the game scene when you're not editing the object?
More details:
I have a class -- call it Map -- that creates its mesh representation at runtime. Map is just a data class; serializable but it's not a MonoBehaviour. When it needs to be represented, I create a MapRepresentation, which is a MonoBehaviour. This class then instantiates a bunch of Meshes based on the map.
So far so good! But I want some kinds of Map to be editable by hand in the editor. Let's call these ManualMaps. To make this great, I wanted to actually have a custom ManualMap inspector that, among other things, shows the representation of the map in the scene, and allows you to click on it and manipulate it in the editor scene. I have some casual handle (pun intended) on how to do this.
My problem is that I am not sure how to correctly create the procedural meshes. If I instantiate a MapRepresentation in OnEnable & make it a child of the ManualMap, well, it never goes away. It's not at all temporary. Do I need to intercept de-selection of the ManualMap & Destroy the MapRepresentation? I mean, this is all starting to feel very clunky and against the grain.
Unity pros, how would you solve this problem?
Is sad to see this question unanswered for so many years... When I'm researching to do something that needs similar functionality.
Your answer
Follow this Question
Related Questions
Null reference exceptions when using a Custom Editor 0 Answers
Custom Editor Search bar 2 Answers
Custom Inspector: Accessing a reference to another MonoBehaviour? 1 Answer
What is a GUILayoutOption[] 3 Answers