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

Telling if a selected object is a prefab in the editor

Discussion in 'Scripting' started by herufeanor, May 28, 2010.

  1. herufeanor

    herufeanor

    Joined:
    May 28, 2010
    Posts:
    33
    So I have a component with a custom editor UI on it, which includes an OnSceneGUI, to draw some extra handles on the object. This all works great, when I'm working with actual instanced objects using this component.

    However, when I have the component attached to a prefab, and select that prefab in the Project window, OnSceneGUI still runs. So, it still displays those extra handles in the scene view, even though the object the handles are supposed to be attached to isn't actually in the scene at all.

    Is there a way to check in OnSceneGUI if the currently selected object is a prefab, so I can not display the handles in that case?
     
  2. herufeanor

    herufeanor

    Joined:
    May 28, 2010
    Posts:
    33
    This has gotten a lot of views, but no answers, so I'm guessing that the answer is no, there is no way to tell if it's a prefab or not.

    Might be a good suggestions for the next update, that either OnSceneGUI isn't run on prefabs at all (probably the best solution, since I can't think of any time you would want to display a GUI in the Scene window for a prefab), or that the function is given some way to know if the selected object is a prefab or not.
     
  3. herufeanor

    herufeanor

    Joined:
    May 28, 2010
    Posts:
    33
    We clearly need a "Report Spam" button here.
     
  4. zeiksz

    zeiksz

    Joined:
    Mar 10, 2019
    Posts:
    10