Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Retrieve custom properties from .fbx file - I'm almost there

Discussion in 'Scripting' started by Thibault_potier, Jul 29, 2021.

  1. Thibault_potier

    Thibault_potier

    Joined:
    May 4, 2021
    Posts:
    46
    Hi

    I want to be able to read custom properties that 3d artist have put on fbx nodes. My purpose is to implement custom behaviour by reading those values. So far I'm able to access them when unity import the .fbx file by using OnPostprocessGameObjectWithUserProperties

    Code (CSharp):
    1. void OnPostprocessGameObjectWithUserProperties(
    2.         GameObject go,
    3.         string[] propNames,
    4.         System.Object[] values)
    5.     {
    6.  
    7.         Debug.Log(go.name +" -----------------------------------------------");
    8.  
    9.         for (int i = 0; i < propNames.Length; i++)
    10.         {
    11.             string propName = propNames[i];
    12.             System.Object value = (System.Object)values[i];
    13.  
    14.             Debug.Log("Propname: " + propName + " value: " + values[i]);
    15.         }
    16.     }
    But it seems that I have a problem when reading some of the values :/

    properties shown in blender :



    properties retrieved with the above code :



    As you can see, property "type" has now value "0" instead of "rotation"; and property "axis" is now "2" instead of "X".

    The weird thing is that property "nameAtt" has kept its string value "wheel", so I really don't know what to conclude here.

    Does anyone have explanations, tips, or solutions to be able to retrieve properly those custom attributes? :p
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Perhaps words like "type", "rotation" and "axis" are on some sort of undocumented reserved list. Try changing their names and values as an experiment to other things like "myType", "myRotation" and "myAxis" or something along those lines and see if they show up that way.
     
  3. eightbitbrainpower

    eightbitbrainpower

    Joined:
    Dec 8, 2017
    Posts:
    6
    Hey there! How is it going, any news on that subject ? I find this is a quite important feature, hope you sorted it out and willing to enlight us ;)
     
  4. Thibault_potier

    Thibault_potier

    Joined:
    May 4, 2021
    Posts:
    46
    So I don't remember exactly, but the solution was to modified the source .fbx .

    Probably use strings instead of enums in the nodes users properties. But it may also be some change in the export option, when exporting the .fbx with 3ds max.

    In both case, the change was made on the model source in 3dsmax and not when importing it in unity
     
    eightbitbrainpower likes this.