Search Unity

Question about m_Script in YAML Unity prefab format

Discussion in 'Editor & General Support' started by beannt, Feb 25, 2012.

  1. beannt

    beannt

    Joined:
    Feb 25, 2012
    Posts:
    14
    Hi Unity guys, I have some questions about YAML format in Unity 3.5.

    Recently, I have a task to convert all C# script files in my project to external assembly (dll library) since it's too big now and I need to break current project into many smaller ones.

    The converting is very smooth until I faced the problem of converting all mono-scripts in existed game prefab reference to new script in DLL instead of direct plaintext script. My project is so big and include about hundreds of prefabs so I can't convert it by hand (drag and drop new scripts to the prefab).

    After looking into new Unity YAML prefab format, I have come with a solution that I will make a tool to read and replace script reference in the ".prefab" file but other problem come out, I don't know what "fileID" attribute mean ? what the algorithm to gererate it. I have tested importing the same DLL to difference projects and I noticed that this number is the same across projects.

    Here's the example of what I mean

    This is the serialization data of a Monobehavior in DLL file, pls notice the line in red
    --- !u!114 11400004
    MonoBehaviour:
    m_ObjectHideFlags: 1
    m_PrefabParentObject: {fileID: 0}
    m_PrefabInternal: {fileID: 100100000}
    m_GameObject: {fileID: 100000}
    m_Enabled: 1
    m_EditorHideFlags: 0
    m_Script: {fileID: 1343822219, guid: ce180b06ab6da7f4f96f92ae5a28ff61, type: 1}
    m_Name:
    name: Script1
    value: 0

    I think the guid value is the guid of the DLL file, but what the "fileID" ? I have no clue of what this number mean ? I think it's a hash code or some static number :confused:. I want to know how to generate it ( Classname -> "method to gernate" -> fileID number ) to build automation replacing tool.

    Is anyone in Unity can help me ?

    Thank you for your support.
     
    Last edited: Feb 25, 2012
  2. KumarBurela

    KumarBurela

    Joined:
    May 29, 2011
    Posts:
    23
    Hello Beannt ;i am new of unity.can we implent networking concepts in unity also?
     
  3. beannt

    beannt

    Joined:
    Feb 25, 2012
    Posts:
    14
    Sorry Rajju, your question is not related to mine and I don't know the answer. I have tried various methods (get Type hashcode, Type name hash code etc..) but I can't figure out how to compute the fileID value :(
     
  4. ubik2

    ubik2

    Joined:
    Feb 29, 2012
    Posts:
    3
    Bit of a necro on this thread, but figured I could add a bit of info.

    When Unity encounters a file for the first time, it generates a .meta that will be used to track this file in the future. That .meta file contains a generated guid. The mechanism for generating these isn't too important (you should be able to put in any valid guid), but it is used to track the reference. This way, you can rename a script that is referenced, and all the prefabs that point to it will still work.

    I think the fileID is a reference to which object within that referenced file. In many cases, this will be a reference to another object within the same file, in which case the guid is left out. Otherwise, it's the part after the in the lines that start with '---'
     
  5. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,627
    I can't tell you how to generate the hashed number, but I did some testing on the subject and have determined that, in the case of classes within a DLL, the fileId is based on the namespace name and the class name. That means changing a class name or a namespace within your DLL will break your prefabs and scenes unless you first determine your new fileIds and update the references project wide. See my post here for more details.
     
  6. spark-man

    spark-man

    Joined:
    May 22, 2013
    Posts:
    96
    Hi all

    I am in finding solution same as OP

    How can I find the fileID of prefab (not dll) ?

    Anyone from unity can help?
     
  7. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    What do you mean the fileID of a prefab? fileID is the id of something within it's file. So if it's a script in a dll, it's the ID inside that dll (see where it's located here).

    If you're looking at a scene file, the fileID of prefabs in the m_ParentPrefab field seems to always be "100100000". For the gameObject that's referencing the prefab, the fileID is just the prefab's file id internally in the same scene fiel.

    What's the exact problem you're trying to solve?
     
  8. spark-man

    spark-man

    Joined:
    May 22, 2013
    Posts:
    96
    --- !u!1001 &1754024618
    Prefab:
    m_ObjectHideFlags: 0
    serializedVersion: 2
    m_Modification:
    m_TransformParent: {fileID: 0}
    m_Modifications:
    - target: {fileID: 4100075464471566, guid: 5f78cd56c1afd4280b0b4f108449b200, type: 2}
    propertyPath: m_LocalPosition.x
    value: 0
    objectReference: {fileID: 0}
    - target: {fileID: 4100075464471566, guid: 5f78cd56c1afd4280b0b4f108449b200, type: 2}
    propertyPath: m_LocalPosition.y
    value: 0
    objectReference: {fileID: 0}
    - target: {fileID: 4100075464471566, guid: 5f78cd56c1afd4280b0b4f108449b200, type: 2}
    propertyPath: m_LocalPosition.z
    value: 0
    objectReference: {fileID: 0}
    - target: {fileID: 4100075464471566, guid: 5f78cd56c1afd4280b0b4f108449b200, type: 2}
    propertyPath: m_LocalRotation.x
    value: 0
    objectReference: {fileID: 0}
    - target: {fileID: 4100075464471566, guid: 5f78cd56c1afd4280b0b4f108449b200, type: 2}
    propertyPath: m_LocalRotation.y
    value: 0
    objectReference: {fileID: 0}
    - target: {fileID: 4100075464471566, guid: 5f78cd56c1afd4280b0b4f108449b200, type: 2}
    propertyPath: m_LocalRotation.z
    value: 0
    objectReference: {fileID: 0}
    - target: {fileID: 4100075464471566, guid: 5f78cd56c1afd4280b0b4f108449b200, type: 2}
    propertyPath: m_LocalRotation.w
    value: 1
    objectReference: {fileID: 0}
    - target: {fileID: 4100075464471566, guid: 5f78cd56c1afd4280b0b4f108449b200, type: 2}
    propertyPath: m_RootOrder
    value: 2
    objectReference: {fileID: 0}
    m_RemovedComponents: []
    m_ParentPrefab: {fileID: 100100000, guid: 5f78cd56c1afd4280b0b4f108449b200, type: 2}
    m_IsPrefabParent: 0

    I meant fileID which are highlighted in red. How to find fileID? I want to automate adding prefab to scene file through external editor script.
     
  9. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    Those are the modifications to the prefab in a scene. The fileID there is the reference to the modified object inside the .prefab file. So if you open the .prefab in a text editor, you'll find that fileID.

    m_Modifications:
    - target: {fileID: 4100075464471566, guid: 5f78cd56c1afd4280b0b4f108449b200, type: 2}
    propertyPath: m_LocalPosition.x
    value: 0
    objectReference: {fileID: 0}

    That means that this is a modification to the object with the ID 4100075464471566 inside the prefab with the guid 5f78cd56c1afd4280b0b4f108449b200. The thing that has been modified on that object is the property m_LocalPosition.x.

    So you've changed the .position.x of some transform in the prefab in your scene.
     
    spark-man likes this.
  10. spark-man

    spark-man

    Joined:
    May 22, 2013
    Posts:
    96
    Great, thank you so much! :)

    --- !u!1001 &1754024618
    Prefab:

    And do you know how to find number highlighted in red?
     
  11. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    That's that object's fileID (as in the object's ID inside the scene). So if you assign that object to a script on some other object, that'll be the value that shows up there.
     
  12. Emericanized

    Emericanized

    Joined:
    Apr 30, 2010
    Posts:
    23
    Hi @Baste, I'm curious if you could tell me what the final "Type" property refers to? I see have seen a lot of them turning into type: 3s when scenes get modified. An example:
    Code (CSharp):
    1.    
    2. ...
    3.     - target: {fileID: 1591459483465278, guid: ceddb85945997ea46a35e0efd073cce0, type: 3}
    4.       propertyPath: m_StaticEditorFlags
    5.       value: 4294967295
    6.       objectReference: {fileID: 0}
    7.     m_RemovedComponents: []
    8.   m_SourcePrefab: {fileID: 100100000, guid: ceddb85945997ea46a35e0efd073cce0, type: 3}
    9. ...
    10.  

    Could this be triggered by having upgraded unity since the scene was last saved?
     
  13. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    I don't actually know! If you upgraded from 2018.2 to a later version, it could be related the new prefab system, but idk.

    @harryr, you mentioned the file format documentation in a different thread. Any input, and any chance of having info about what the type field is to the docs?
     
  14. harryr

    harryr

    Unity Technologies

    Joined:
    Nov 14, 2017
    Posts:
    38
    Hey Baste, here's what the type field represents:
    0, 1, 3 = Object lives in Library/metadata
    2 = Object lives in the asset

    Related docs: IsNativeAsset, IsForeignAsset