Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Get script name from info in asset YAML

Discussion in 'Scripting' started by DinostabOMG, Aug 15, 2023.

  1. DinostabOMG

    DinostabOMG

    Joined:
    Jan 4, 2014
    Posts:
    26
    One thing that's hard is to understand what changes have been made in a .prefab, .asset, .mat, or other asset file by looking at the diff in version control. For example, on a .mat file I see this diff:

    Code (csharp):
    1.  Material:
    2.      - _EmissionColor: {r: 0, g: 0, b: 0, a: 0}
    3.      - _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
    4.    m_BuildTextureStacks: []
    5. +--- !u!114 &3756403773803337737
    6. +MonoBehaviour:
    7. +  m_ObjectHideFlags: 11
    8. +  m_CorrespondingSourceObject: {fileID: 0}
    9. +  m_PrefabInstance: {fileID: 0}
    10. +  m_PrefabAsset: {fileID: 0}
    11. +  m_GameObject: {fileID: 0}
    12. +  m_Enabled: 1
    13. +  m_EditorHideFlags: 0
    14. +  m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
    15. +  m_Name:
    16. +  m_EditorClassIdentifier:
    17. +  version: 5
    18.  
    So I know the part that tells Unity what script this is, is the line: `+--- !u!114 &3756403773803337737`

    And I saw in the docs that the 114 indicates that this is a MonoBehaviour based on a script. I presume that the part after the `&` indicates what this script is?

    Or is it the other line: `+ m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}`?

    But in either case, how do I go from that to knowing what script has been added to this material? It seems to have happened automatically and it's unclear in the editor.

    More generally, it would be nice to know this at a glance from looking at the diff. Seems like it could be added as a comment in the YAML pretty easily! But it's overkill to get involved in how Unity serialization works for our project at this stage. However I would like to suggest that to Unity as well.
     
  2. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,495
    I need to clear up several things here. First of all
    No, the number after the ampersand is just the instance ID within the file in case other objects within the same file want to refer to this instance. See the docs for more info.

    The next thing is from Unity's perspective there's no difference between a MonoBehaviour and a ScriptableObject. They are literally the same thing on the native side. The main difference is that a ScriptableObject is not attached to a gameobject. Since your m_GameObject reference is null, this is most likely a ScriptableObject

    Finally, yes, the "m_Script" indicates the MonoScript asset that indicates the actual Mono / .NET class that belongs to this instance. The GUID is the asset ID of the script file. So you would need to search for that asset.

    Note that the instance has the hideflags set to 11 which is a combination of

    Code (CSharp):
    1.     HideInHierarchy = 0x1,
    2.     HideInInspector = 0x2,
    3.     NotEditable = 0x8,
    So you probably won't see that instance inside Unity and the only field is has is called "version". So it might be an internally used class or you have some asset installed that has added this class. A quick google search showed that this GUID belongs to "AssetVersion.cs" which is part of the universal rendering pipeline package. As already assumed it's part of a package and tracks the asset version (for whatever purpose). See this thread which is related.

    About your suggestion to add comments, I don't see how this is going to help much or where you want to draw the line what information should be added as comments. If you would have known that the script is called "AssetVersion.cs", whould that have helped you?
     
  3. DinostabOMG

    DinostabOMG

    Joined:
    Jan 4, 2014
    Posts:
    26
    > About your suggestion to add comments, I don't see how this is going to help much or where you want to draw the line what information should be added as comments. If you would have known that the script is called "AssetVersion.cs", whould that have helped you?

    Yes, that would have helped me. Our coworkers do reviews of each others' merge requests, and these are completely inscrutable. That's precisely the suggestion.

    Since that is not on the table in the short term, however, is there a way to find out what the script name is from the GUID aside from googling? That will only work if it's not a user script.
     
  4. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,495
    Yes, inside the editor you can simply query the AssetDatabase with AssetDatabase.GUIDToAssetPath.