Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Hiding Objects in Scene Editor?

Discussion in 'Editor & General Support' started by corlenbelspar, May 8, 2015.

  1. corlenbelspar

    corlenbelspar

    Joined:
    May 1, 2015
    Posts:
    14
    Is there any way to have objects hidden or created during runtime in a scene so I don't have t clutter up the scene with things like my scanline tiled sprite for scanline effects?
     
  2. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,986
    Lots of options. You could nest them, and turn off the parent (turn on at runtime). You could use layers and turn them of in editor. You could also store as prefabs (one or bunches) and spawn them. Many ways, some have different costs though.
     
  3. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Don't scale objects to zero :)

    If you take the SetActive option, bear in mind that GameObject.Find won't find inactive objects, but Transform.FindChild does. You may hold a reference in your code to those game objects and then activate/deactivate them (or a parent group).
     
  4. corlenbelspar

    corlenbelspar

    Joined:
    May 1, 2015
    Posts:
    14
    Well I was searching and I found a good way to do it is to Instantiate prefabs but I couldn't get it to work because I'm using C# and everything I found was in javascript and I'm by far not even advanced enough to write code without asking these simple questions. :p
     
  5. Kronnect

    Kronnect

    Joined:
    Nov 16, 2014
    Posts:
    2,876
    Yes, use prefabs as much as possible in Unity. Prefabs are a great componentization pattern, and will allow you to store and reuse quickly pack different relates structured together: hierarchy of gameObjects, materials, components (behaviours), ...

    The way you instantiate them in C# usually is:

    - You load them from Resources folder:
    Code (CSharp):
    1. GameObject x = Resources.Load<GameObject>("path_from_resources_folder/name of prefab file).
    - Instantiate as many times you need:
    Code (CSharp):
    1. GameObject instance = GameObject.Instantiate(x) as GameObject
     
  6. Deleted User

    Deleted User

    Guest

  7. corlenbelspar

    corlenbelspar

    Joined:
    May 1, 2015
    Posts:
    14
    I managed to create the object with the instantiate code that you posted Thrawn75, but now I can't seem to manipulate the object that was created.