Hidden objects in game but not in editor?

This is probably a bone headed question but how would I create an object that draws in the editor but not in the game itself? I want it to have a mesh in the editor so I can place it properly but it needs to be invisible inside the game proper.

I assume this is simple but I don’t see it. :slight_smile:

Just disable or remove the Renderer component in the Inspector.

I could do that but is there no automated way to say “draw this in the editor, but not when I’m playing the game”?

I believe you allready know that if you change its tag to editor only in the inspector, it goes away in the build. But you might need it to just have its renderer off…

You might be able to set a new tag, and use some kind of detection similar to browser detection, but for player instead, to define whether a script turns the renderer off or not?
AC

can’t you just use the same method as in the first car tut - for waypoints they have emptys with a waypoint image that’s kept in an “Editor” folder if i recall - they show up in the editor but not in builds.

EDIT: gizmos are what you what you want i think:

http://unity3d.com/Documentation/ScriptReference/Gizmos.html

1 Like

I think that works for little widget icons. I don’t believe you can show a mesh with it.

seems you are right - what is it for willem a separate collision mesh?

what’s the context? - is there a reason why turning off the renderer is an issue, do you have to do this on many objects?

if you need the object (ie collision mesh), throw a script on it with renderer.enabled = false in your start function. check the script ref for correct syntax.

At SeriousGames we just have our own DrawWireFrameMesh that we call from an OnDrawGizmosSelected. Works fine (is a bit slow, but that’s ok for our case).

Or you could create a Layer called Editor and have it visible in the Scene View but have it not rendered in all of your cameras. Then place all those meshes in that layer. Might be good for your situation, who knows.

-Jon

4 Likes

Essentially, what I’m building is a teleporter. I have a teleporter mesh that is in the world and I have a teleporter destination object that I place and associate with the original teleporter.

I want the teleporter destination object to be visible in the editor but I don’t want it to be there when I play the game.

Right now I’m using a mesh so I can make it the same size and shape as the player (for accurate positioning), so if this could be done with a mesh it would be great.

This must be possible as I notice that lights and things don’t draw inside of the game…

OK, I guess I can get around it with this code in the script for the teleporter destination:

function Start()
{
	GetComponent( MeshRenderer ).enabled = false;
}

…would be nice if there was an automated solution for this though.

Can’t you just use an empty game object as the destination object? You’ll see it in the hierarchy, and you’ll see its position in the editor when you click it. But you won’t see it in the game view at all because it is essentially invisible.

My suggestion is to create a box Gizmo and size it to fit your player’s size. This code from the VisibilityCullingArea script does just that.

function OnDrawGizmosSelected ()
{
	// Draw camera outline
	Gizmos.color = Color.yellow;
	GL.PushMatrix();
	GL.MultMatrix(transform.localToWorldMatrix);
	Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
	GL.PopMatrix();
}

Im still not convinced that switching his object tag to “editor only” is not the solution. I might be misreading the question but try it Willem. Then do a build
AC

I have it working now with my “enabled = false” hackery above. I’m moving on to other parts of the project now but if it gets to be painful down the road, I’ll revisit this thread.

Thanks everyone for the responses! This is a great community.

The best solution I have found is to create an Editor Only layer. Then turn off that layer in the cameras culling mask. Then that object will display in the editor but not in game.

2 Likes

Are you serious? Did you check the date of the last post in this thread?!

Check my answer here,
http://answers.unity3d.com/answers/1124792/view.html

For me, tagging with “EditorOnly” does work. Thanks, AaronC!

1 Like