Search Unity

Text based asset, fileID, guid

Discussion in 'Scripting' started by ZoltanErdokovy, Oct 4, 2013.

  1. ZoltanErdokovy

    ZoltanErdokovy

    Joined:
    Aug 23, 2012
    Posts:
    102
    I have two projects, one uses a plugin with source code, the other uses the DLL version of the same plugin.
    The plugin creates custom assets files with tons of ScriptableObjects in them. In both projects assets are
    forced to be text based.

    I'm trying to move assets between these projects but the trouble is that off the bat they don't load at all.
    I compared newly created assets files from both projects and saw these kind of differences:

    Writing a parser which replaces one value with another would be simple, but there are about 40 classes
    involved so manually gathering the replacement pairs is something I'd like to avoid. Is there a way to get
    fileID and guid values from code?
     
  2. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Not sure how or what a file id is used for, but to get a guid:

    Given an object someObject:
    Code (csharp):
    1. string assetPath = AssetDatabase.GetAssetPath(someObject);
    2. string guid = AssetDatabase.AssetPathToGUID(assetPath);
     
  3. ZoltanErdokovy

    ZoltanErdokovy

    Joined:
    Aug 23, 2012
    Posts:
    102
    Unfortunately it gets the guid for the asset and not the guid for an object inside the
    asset.
     
  4. yoyo

    yoyo

    Joined:
    Apr 16, 2010
    Posts:
    112
    Note that only files have GUID's -- all the assets in a particular asset file (for example all the ScriptableObject classes in a DLL) will have the same GUID.

    For a loose script, the fileID is always 11500000, which is the class ID for MonoScript multiplied by 100,000.

    For classes in a DLL, the fileID seems to be related to the namespace and class name of the type, but I wish I knew the relationship -- it's certainly not the C# GetHashCode() of the type name, nor is it the instance ID of the MonoScript asset. (I briefly thought that in the DLL case too the fileID is also a multiple of the MonoScript class ID, 115, but then realized Windows Calculator in Programmer view doesn't show any decimal places, whoops!)
     
    Last edited: May 15, 2014
    lin_mdotor likes this.
  5. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Not sure to follow... But if you create asset in two project, even if they are created the same way, they will never have the same Guid.
     
  6. Lambda Knight

    Lambda Knight

    Joined:
    Mar 8, 2011
    Posts:
    23
    lin_mdotor likes this.
  7. ZoltanErdokovy

    ZoltanErdokovy

    Joined:
    Aug 23, 2012
    Posts:
    102
    Wow, good job, thanks!
     
  8. lin_mdotor

    lin_mdotor

    Joined:
    Apr 21, 2015
    Posts:
    2
    Very old post, but I searched a solution to the changes in Scriptable Object's guid embedded in DLLs, and after a long time I found the reason of these guid changes.

    The m_Script: {fileID: 936005545, guid: b4c82f59e61bef74e92f25aa89b92e99, type: 3} is the reference to the class of the ScriptableObject.
    If your asset has the guid:XXX referenced in m_Script, is because the main class "CusomAsset.cs" have the guid XXX in its .meta file.Some changes in these .meta files can change the guid, and this will change the m_Script{guid} of the Scriptable Object's instances.

    If you have the source code of the plugin, you probably can change the guid of the .meta file, and make it compatible with the DLL guid.

    Source: http://www.ninjacrab.com/2013/03/01/unity-script-meta-files/