Search Unity

I want to know in Unity3d has relative souce file like Unreal Engine?

Discussion in 'General Discussion' started by fablelie, Jul 16, 2018.

  1. fablelie

    fablelie

    Joined:
    Aug 2, 2016
    Posts:
    1

    some thing like this.
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I have no idea what a relative source file does. Lazy googling hasn't really revealed anything for me. Care to elaborate on what it does, and then we can tell you how to accomplish the equivalent in Unity.
     
  3. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    I believe this is referring to relative vs. absolute paths.

    From wikipedia:
    So an absolute path might be "C:\Projects\YourGame\Assets\Textures\whatever.png", whereas a relative path will be something like "..\Textures\whatever.png".

    As for Unity, since you can move project folders around and everything still works it's clearly not using absolute paths in the classic sense. My guess is that all paths are stored relative to the project's root directory, but it's honestly never mattered to me so I've never checked.
     
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Paths to assets are stored in the asset database. (I would assume relative, internally). But, pathing is not critical as it’s handled by the asset database. For external files, it’s absolute.
     
    Joe-Censored and Ryiah like this.
  5. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    From what I understand unity uses the GUIDs and not the paths at all, which is why you need to move things inside of the Unity editor if you want it to continued working
     
    Kiwasi likes this.
  6. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    Yes, (ish). The guid is the unique identifier for an ement’s entry in the AssetDatabase. The path to assets location is stored there. When you move something in the editor the path is updated. If you move outside of that, the path isn’t updated and broken.
     
    QFSW likes this.
  7. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,051
    To get full or relative path:
    Code (CSharp):
    1.  
    2.         public GameObject thingToFind;
    3.        
    4.         public void ShowPath()
    5.         {
    6.             var path = AssetDatabase.GetAssetPath(thingToFind);
    7.             var assets = Application.dataPath.Replace("/Assets", "");
    8.             // relative to Assets folder
    9.             Debug.Log(path);
    10.             // full path
    11.             Debug.Log(assets+"/"+path);  
    12.         }
    13.  
    14.  
    Result:
    upload_2018-7-18_0-48-2.png
     
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,147
    This. It's easy to verify too. Simply create a blank project in the newer releases of Unity, open the AssetDatabase binary file in a text editor (like Visual Studio Code), and search for the name of the scene file that the latest release generates with a blank project.

    SceneFileEntry.png
     
  9. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Unity is designed in a manner where you as the game developer should not need to be concerned with the path of your source files in most cases, as you access them through references established in the editor's inspector starting from objects (and their attached components) you place in a scene rather than from their file path on disk. This is regardless of how the information is tracked by Unity internally (interesting discussion above though).

    A couple exceptions are when loading assets at runtime either from a Resources folder or from an Asset Bundle, where you can use a relative path to the asset from its Resources folder or of the asset bundle respectively, not their absolute path on disk.

    https://docs.unity3d.com/ScriptReference/Resources.Load.html
    https://docs.unity3d.com/ScriptReference/AssetBundle.LoadAsset.html