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.

Opening a prefab in prefab mode from script

Discussion in 'Prefabs' started by mudloop, Jun 25, 2019.

  1. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,105
    Hi,

    As the title says, I'd like to know how to open a prefab in prefab mode from an editor script. I've been unsuccessful in my google searches so far.

    Use case is I'd like to build an editor panel that gives me quick access to the prefabs I need to edit frequently. Would save some time as opposed to finding them in the project panel (or scene, in some cases) each time.

    Any tips would be appreciated. Thanks!
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    5,848
    AssetDatabase.OpenAsset.

    @runevision, you're the one that told me about that method for opening assets in prefab mode. There seems to be one thread created every second day about "how do I open the prefab mode from editor script": It seems like it's really, really not obvious how to do this. You guys should add a utility method to one of the Prefab (PrefabUtility, PrefabStageUtility?) classes that people actually find.
     
    SugoiDev and SmartMediaNL like this.
  3. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,105
    Thanks! And sorry for asking something that apparently gets asked a lot :)
     
    Baste likes this.
  4. Supergeek

    Supergeek

    Joined:
    Aug 13, 2010
    Posts:
    103
    Unfortunately, when using OpenAsset I lose my selection in the Project window, which triggers another OnSelectionChanged().
     
unityunity