At the moment my method looks like this:

public static void MethodName<T>(T asset) where T : Object { //Получаем оригинал объекта. Если метод вернул null - значит asset и есть оригинал T origin = PrefabUtility.GetCorrespondingObjectFromOriginalSource(asset) ?? asset; //Получаем путь до объекта var path = AssetDatabase.GetAssetPath(origin); ... } 

Faced with some problem after the transition to Unity 2018.3 - in it the units updated the system of prefabs and naturally broke everything that was connected with it.

When we send the prefab instance on the scene to this method, everything works fine, because The original is located and you can get the path to it.

But if you edit a prefab in a new special stage for prefabs everything goes really bad. Because this instance is not instanced, but the "prefab" in the unit's understanding, the method returns null, but at the same time the asset continues to refer to the object from the scene and returns the string.Empty the file path of the object on the scene can not be.

Previously, when an object simply stood out in the folder with files and was drawn in the inspector everything worked fine, because Asset referred to a specific file in a folder, not to the scene.

    1 answer 1

    Understood in the end.

    Now Unity has a magic namespace UnityEditor.Experimental.SceneManagement , in which there is a class PrefabStageUtility that allows you to get some information from the current "prefab scene", for example, its current state - PrefabStage , which already contains a lot of interesting fields, for example, so needed me prefabAssetPath .

    It is through this utility that the entire scene partially works and the prefab is saved. (I had to download the source of Unity for this and look for the editor of this scene).