How to check if the edited instace is a prefab or How to know we are in prefab editing mode

Hi,

Trying to battle this one out as EditorUtility.IsPersistent(go) is now obsolete to check if we are dealing with a prefab asset or prefab instance.

so, within a script attached to a prefab that we are editing using the new prefab workflow, that is within its own scene. How can we know we are editing a prefab? since now, it’s actually an instance of the prefab we are editing.

PrefabUtility.GetPrefabAssetType(go) returns NotAPrefab

currently the only way I found is by querying the .scene of the gameobject and if the scene name is the same as the gameobject name and the scene path is empty then that must mean this is the prefab source. But that is not very clean.

Thanks :slight_smile:

Jean

Two different examples for my Unite LA talk:

1 Like

Hi,

Woah! ok, thanks for that, I would have had a hard time figuring all of this…

Is the UnityEditor.Experimental namespace likely to change when 2018.3 is going to go out of beta?

Bye,

Jean

The Experimental API will not change in 18.3 but will be moved in 19.x

Hi,

ok, thanks for you time and infos, have a good day!

Bye,

Jean

Hi, the API still seems to be experimental in 2019.3 (Unity - Scripting API: PrefabStage).
Any news on when and where it will finally land?

I am currently detecting whether the user is in PrafbStage or not with the code below, but it seems a bit risky to put this into production (AssetStore asset) since the API location may change.

private static bool isInPrefabStage()
{
#if UNITY_2018_3_OR_NEWER
    var stage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
    return stage != null;
#else
    return false;
#endif
}

Thanks,
Georg

Ping :stuck_out_tongue: Knowing this is pretty important for editor tool. I’ve tried various workarounds to avoid using the experimental PrefabStageUtility but I couldn’t find a system that works in 100% of the cases.

My “resolution” was to just keep using the experimental namespace until it breaks, which has not happened to me yet. It is also in the latest version: 2020.1, so I don’t think it will go away soon.

In my opinion an API which has been existing unchanged for three major releases (2018, 2019, 2020) is no longer experimental. I understand that the reason for not changing it is probably backwards compatibility, but being experimental for so long defeats the purpose of the namespace imo.

It would be nice to have some kind of newsletter where you can sign up and get notified if something breaks in the namespace/classes which you have signed up for. I know it’s a big wish, but that would spare me to check which versions of unity are breaking my code (at least API wise). This could be automated too. Just scan for API changes in releases/docs and send the emails.

2 Likes

The are a lot of changes to the API in 2020.1; for example PrefabStage inherits from a different class. However, it’s mostly backwards compatible. We wanted to get it out of experimental API for 2020.1 but due to issues with the API updater and various build and test infrastructure, it hasn’t been possible. It’s actively being worked on though. The API, once out of experimental, will be the same as in 2020.1, just moved out of experimental. The API updater should handle almost all cases of this automatically.

1 Like

Thanks for the info. So the API updater will attempt to fix it automatically, that’s good news.