Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Privertex · Jun 25, 2016 at 02:36 AM · editor3dscript.

Hiding helper geometry during runtime

I'm trying to use a collection of "helper geometries" inside the editor. These helpers mainly provide location and direction reference for my scripts for interactable game objects such as furniture, doors, etc. and are assigned to my prefabs. Upon interaction with one of those objects, the player character will locate the helper geometry and move to it before initiating the interaction animation. Furthermore they serve as a visual aid so I don't accidentally end up blocking any of these game objects. While being visible in the Unity editor these helpers need to be invisible during game mode.

My current implementation is to place all of these "helper geometries" on a seperate layer which is excluded from being rendered by the camera. But maybe there is a more practical way to deal with this?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by tanoshimi · Jun 25, 2016 at 08:27 AM

To visualise locations, directions, or volumes in scene view only, you should use gizmos.

alt text


gizmos.jpg (77.8 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Privertex · Jun 25, 2016 at 10:01 AM 0
Share

Thanks, that helped.

Here is my current script if any artist like me ever needs a reference to start from.

     public class InteractionPoints : $$anonymous$$onoBehaviour {
 
     public $$anonymous$$esh Interaction$$anonymous$$esh;    //Custom mesh goes in here
 
     // Use this for initialization
     public void OnDrawGizmos () {
         Gizmos.color = Color.green;
         Gizmos.DrawWire$$anonymous$$esh (Interaction$$anonymous$$esh, transform.position, transform.rotation, transform.localScale);
     }
 }
avatar image
0

Answer by Invertex · Jun 25, 2016 at 03:01 AM

Have you tried using Platform Dependent Compilation?

http://docs.unity3d.com/Manual/PlatformDependentCompilation.html

     #if UNITY_EDITOR
 //Unity Editor only code here
     #endif

is what you want to wrap those display helper object operations in.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by -_-_-_-_-_ · Jun 25, 2016 at 07:43 PM

@Privertex Try This:

 using UnityEngine;
 using System.Collections;
 
 public class thing : MonoBehaviour {
 
     void SetVisibility (bool Visibility, bool Collidable, GameObject target) {
         
         MeshRenderer renderer = target.GetComponent <MeshRenderer> ();
         Collider collider = target.GetComponent <Collider> ();
 
         if (renderer)
             renderer.enabled = Visibility;
         if (collider)
             collider.enabled = Collidable;
     }
 
     void SetVisibility (bool Visibility, GameObject target) {
     
         MeshRenderer renderer = target.GetComponent <MeshRenderer> ();
 
         if (renderer)
             renderer.enabled = Visibility;
     }
 }

This code disabled the mesh renderer to make it invisible for camera, in additionally, this also sets the collider so nothing collides into it.

The if statements detect if there is no certain coponent on the gameObject, it will not attempt to set the enabled property of the component and therefore will not throw an exeption.(Give an error in the Console)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image -_-_-_-_-_ · Jun 25, 2016 at 03:18 AM 0
Share

P.S So, if you want to a GameObject disappear, disable the mesh renderer, which essentially visualizes the $$anonymous$$esh to a Camera. The Collider essentially adds a solid collision to it, so if you want to disable collision, disable the collider.

avatar image
0

Answer by Plattinator · Jun 25, 2016 at 07:43 PM

I put together a little script that you can put on any game object to exclude it from the build and also destroy the game object that it's attached to when testing in the editor.

 using UnityEngine;
 
 /// <summary>
 /// Causes the attached game object and its children to only exist while in edit mode. The game object will not be included
 /// in the build, so there is no performance hit for using this on objects that are purely visual aids in the editor.
 /// </summary>
 [ExecuteInEditMode] // So that OnDestroy will be called if the component is removed while in edit mode.
 public class EditorOnlyGameObject : MonoBehaviour
 {
 #if UNITY_EDITOR
 
     // Called when this component is attached to a game object.
     private void Reset()
     {
         // This will make it so the game object this is attached to won't even be included in the build.
         // Make sure the game object and all of its children are not needed for gameplay and are purely visual helpers in the editor.
         gameObject.hideFlags = HideFlags.DontSaveInBuild;
     }
 
     private void Awake()
     {
         if (UnityEditor.EditorApplication.isPlaying)
         {
             // Destroying the game object will help catch any errors where something was referencing an editor visual helper,
             // since this game object won't even exist in a build.
             Destroy(gameObject);
         }
     }
 
     private void OnDestroy()
     {
         // If this gets removed from a game object while in edit mode...
         if (!UnityEditor.EditorApplication.isPlaying)
         {
             // Reset the game object back to normal so that the game object will be included when making a build.
             gameObject.hideFlags = HideFlags.None;
         }
     }
 
     [UnityEditor.CustomEditor(typeof(EditorOnlyGameObject))]
     private class Editor : UnityEditor.Editor
     {
         public override void OnInspectorGUI()
         {
             base.OnInspectorGUI();
 
             UnityEditor.EditorGUILayout.HelpBox(
                 "This game object and its children only exists while in edit mode!", UnityEditor.MessageType.Warning, true);
         }
     }
 
 #endif
 }

You can also use the game object icon feature (https://docs.unity3d.com/351/Documentation/Manual/GizmoandIconVisibility.html) to stick an icon on any game object. It will only be visible in the scene view of the editor.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

56 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to control GameObjects by Button and Script 0 Answers

How to Make Pickups on a 3D plane? 0 Answers

Im getting this error, CS8025 Parsing Error. 1 Answer

How many ways are there to clamp 3d objects? 0 Answers

Cannot create new C# Script Assets, and files with meta data are missing 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges