Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Textual Scene File Format

Discussion in 'Editor & General Support' started by Robin-Jubber, Oct 16, 2015.

  1. Robin-Jubber

    Robin-Jubber

    Joined:
    Sep 7, 2012
    Posts:
    28
    Hi. I've recently noticed Unity can export its scenes as text files as well as binary data. On the surface that seems excellent for creating an external tool to skip past the unity editor and allow the creation of game levels using something more appropriate. (I imagine it also has advantages for users of SVN)

    However on loading a scene up I'm encountering a problem - how do I know which ID/GUID a particular prefab or object has? Clicking on an object (a prefab in an otherwise empty test scene) with Debug view on shows me an Instance ID of -3384 and a Local Identifier in File of 0.

    Looking at the scene in Notepad++, that prefab is headed with --- !u!1001 &684934842 along with various modifications labelled like
    m_Modifications:
    - target: {fileID: 426754, guid: 2f07691ba0bdea447ba85d4fe01afba8, type: 2}

    So where do I find these guids and fileIDs - they don't appear attached to the sub-objects in my prefab either. And the very long guid - similarly not sure where they come from. Has anybody ever used Textual Scene File Format in a useful way, or does a proper resource exist anywhere? Unity's manual is very sparse on the subject.

    Many thanks,

    Robin
     
  2. LeonH

    LeonH

    Joined:
    Oct 15, 2014
    Posts:
    92
    I think the fileID is exactly what it sounds like, but you need to know which file it's talking about. Sometimes the fileID is presented alone, e.g. {fileID: 426754}. Other times, it's presented along with a guid, e.g. {fileID: 426754, guid: 2f07691ba0bdea447ba85d4fe01afba8}. When it's presented alone, I believe that means the reference exists in the current file. So if you search the same file you see the reference in, you should be able to find the object being referred to. The header for that object will be in the form of the example you mentioned, '!u!1001 &684934842', where the fileID will match the number after the &. In the case where the fileID is presented along with a guid, I believe the object being referenced with that fileID will be found in the asset file for the guid.

    To resolve a guid to an asset's data file, you need to look at .meta files. If you do a find in files of all the *.meta files in your .../Assets/ tree that contain that guid, you should find exactly one, which is the asset associated with that guid. It would be nice if somewhere in the editor UI you could view the guid for an asset, and/or find an asset by entering a guid. Probably some editor extensions in the asset store offer this?

    Oh, and when a fileID is 0, perhaps that means that nothing specifically is referencing it, so it has not been assigned a fileID? I don't know, not really sure about that. Please note that I have no official or authoritative knowledge about this stuff; what I know is based only on observation.

    I've found the text asset format to be absolutely invaluable for many many, reasons. I need to inspect (and sometimes modify) text assets numerous times every day. I can't imagine working efficiently on a large project without it.
     
  3. Robin-Jubber

    Robin-Jubber

    Joined:
    Sep 7, 2012
    Posts:
    28
    Thanks very much Leon! In the end I came to some similar conclusions to you about what those IDs mean - except I decided the whole thing was turning into quite the ballache. So I shortcutted the whole experience - instead I have an empty scene in Unity and load prefabs into it from a menu option.

    MenuItems.cs -
    [MenuItem("WDATHG/Load a map!")]
    static void Loadamap()
    { // standard file reading code }

    and then just read in external files and write code that instantiates prefabs into the scene. That way I don't need to hunt down all those ids. Lazy, but easier!

    Of course my current project is relatively small - just a one-man game. Truly getting to grips with the file format might well be useful on a larger project.

    Thanks again for the reply - I assumed it was such an esoteric aspect of Unity's systems that nobody would ever reply :)

    Cheers,

    Robin.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,227
    You can use AssetDatabase.GUIDToAssetPath to get an asset from a guid. As already stated a guid is the id for an asset(found in the .meta file). You can also use this guid to get to the Unity generated version of the asset which is stored in the Library/metadata directory. Pro tip, you can use Binary2Text.exe to convert the files into a text format to see the contents ;)
     
    LeonH likes this.