- Home /
Clickable empty GameObject in the editor
Hi,
EDIT: I already found a solution (see below).
I want to create some waypoints, and I want to be able to select them in the editor window. Currently I use empty GameObjects with a Waypoint script attached, which draws gizmos for them. But I cannot select them in the Editor, because there is nothing to select (no geometry, only the gizmo).
But I want to be able to select them in the editor, like one can select a camera object. Does anyone know a solution to this?
EDIT: Like always, I found the solution right after I posted the question. It seems that Gizmo.DrawCube is not clickable, but Gizmo.DrawIcon is - I don't quite know why, but okay, now it works. If someone knows WHY this works this way or how to have a clickable Gizmo.DrawCube - thats the question know :)
Answer by fherbst · Nov 02, 2010 at 09:27 AM
Solution found, see EDIT in my question. This answer is just to clean things up (so everyone looking for it can find it solved).
It seems that Gizmo.DrawCube is not clickable, but Gizmo.DrawIcon is.
Answer by AlanChatham · May 19, 2011 at 06:21 AM
I've found that by attaching a mesh to my waypoing object, I've been able to select and move it around inside the editor with clicking/dragging.
Answer by DapperDirewolf · Feb 16, 2018 at 05:42 AM
Unfortunately this answer didn't work for me - though I'm not sure if it's because I used a custom Gizmo icon or not.
My alternative which seems to be working pretty well is as follows:
Using a 3D / 2D mesh renderer (I used a 3D Sphere Mesh with a flat white material - though a Sprite Renderer will probably work just as well) I am able to select and manipulate the Waypoint as easily as any other object.
Then, in the script I use to manage my waypoints, I loop through every instance of a waypoint and then Destroy the MeshRenderer component on void Start (). This means that while the mesh component is visible in the editor view, all are destroyed immediately upon scene launch and therefore not visible to the player.
Hope this helps somebody!
I am working on my own (similar) solution that quickly allows me to make levels for my space invader game and while I am not finished, I am working on my own editor for my waypoints (I call them nodes, still new to na$$anonymous$$g conventions), and that's where I started running into issues when I wanted to save/edit/test, my code was getting too complex too fast with my previous setup with serialization. Which eventually lead me to the path (pun intended) of creating my own system separated from unity easy to serialize to keep these simple for myself, but interfaces with it quite nicely. I keep a static Dictionary of my nodes, with a static Dictionary of paths that correlates with the nodes in the node Dictionary. The only time the points are represented as gameobjects is when I am using my own editor to edit the level and place nodes. This system also allows me to load and save points and paths without converting gameobjects to an ordered list of nodes, when they can just be nodes and only be converted to gameobjects when level editing. However I do intend to add node gameobjects that are "smart" nodes, but only if they requires the power of a gameobject. I learned to compartmentalize everything, and only use unity when you have to if it can be done outside of it! Hopes my recent insights help!
Your answer
Follow this Question
Related Questions
Select un-selectable Objects with mouse. 1 Answer
Use for loops and still assign gameObjects in editor 1 Answer
Objects created in Editor script lose their reference after Play/Stop? 1 Answer
Mark gameobject field as changed from prefab 2 Answers
Initializing List of generic type via editor - Doesn't work? 1 Answer