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

TriLib UserProperties Always Null

Discussion in 'Assets and Asset Store' started by cv_dg, Oct 18, 2021.

  1. cv_dg

    cv_dg

    Joined:
    Sep 19, 2019
    Posts:
    5
    Hi,

    I am trying to get access to the custom properties in an FBX but it seems to always return 'null'.

    Code (CSharp):
    1. IDictionary<GameObject, IModel> allModels = assetLoaderContext.Models;
    2. foreach (KeyValuePair<GameObject, IModel> modelPair in allModels)
    3. {
    4.     Debug.Log(modelPair.Value.Name); // Outputs name just fine
    5.     IDictionary<string, object> userProperties = modelPair.Value.UserProperties; // Always null
    6.     if (userProperties == null)
    7.         continue;
    8.     // Never reaches this code
    9.     foreach (KeyValuePair<string, object> property in userProperties)
    10.     {
    11.         Debug.Log($"Key: {property.Key} --> Value: {property.Value}");
    12.     }
    13. }
    I made a test_cube.fbx that has a property:
    "test_prop": "abc123"

    When I look at this FBX in Blender or Maya, I can see the custom property just fine, but it doesn't seem to work when imported with the library.

    Anyone know how to get this to work?

    Cheers,
    Charlie
     

    Attached Files:

    Last edited: Oct 18, 2021
  2. cv_dg

    cv_dg

    Joined:
    Sep 19, 2019
    Posts:
    5
    Nevermind, I figured it out. You need to create a mapper that plugs into the options:
    Code (CSharp):
    1. AssetLoaderOptions options = AssetLoader.CreateDefaultLoaderOptions();
    2. options.UserPropertiesMapper = ScriptableObject.CreateInstance<UserPropertiesMapper>();