EdyJ / blender-to-unity-fbx-exporter

FBX exporter addon for Blender compatible with Unity's coordinate and scaling system.
MIT License
1.01k stars 105 forks source link

Custom properties lost #21

Open Crikster opened 3 years ago

Crikster commented 3 years ago

Hi, i think it wold be amazing if theres an option to export custom properties, they are getting lost in the way.

thanks!! Cris

EdyJ commented 3 years ago

I'm definitely interested in this. Could you provide an example file with those custom properties? Also, please describe how to read them in Unity.

Crikster commented 3 years ago

Sure no problem, here a link with a blender file, and some screenshots. https://www.dropbox.com/sh/l3sm891mncvzxaj/AADCgZ6MFXqgTavGCQl7lXMla?dl=0 So basically the custom properties are just Generic properties the user can define, in my case i am using it for filtering of objects. to create different variations. in the screenshots:

Blender: -object custom properties ubication. -blender default fbx export location of custom properties.

Unity: -Unity screenshot of my custom script to load this custom properties and filter dynamically.

hope this helps! and thanks for the interest!

EdyJ commented 3 years ago

Thank you for the file and the screenshots! In your custom script, which Unity API methods are you using to access the custom properties? I'll write a simple script to test they work.

Crikster commented 3 years ago

HI sorry for my delayed answer, is a custom script done by another company :(

EdyJ commented 3 years ago

I shouldn't need the entire script, only the Unity API methods and properties being used. Please understand that I need to be able to reproduce the case in Unity in order to fix it.

EdyJ commented 3 years ago

Closing this issue, as I have no way to reproduce it in Unity.

swingingtom commented 1 year ago

@EdyJ thanks for the plugin 👍. I was struggling with nested empties

I can confirm that custom properties are lost during export. The way to check it in unity is to make a AssetPostProcessor script that post process models, similar to what is there https://docs.unity3d.com/ScriptReference/AssetPostprocessor.OnPostprocessGameObjectWithUserProperties.html

Here is one, paste it in a unity asset folder. It simply lists all custom properties found in FBX. FBXCustomPropertiesListing

using System;
using UnityEditor;
using UnityEngine;

    public class FBXCustomPropertiesListing: AssetPostprocessor
    {
        void OnPostprocessGameObjectWithUserProperties(GameObject go, string[] propNames, System.Object[] values)
        {
            for (int i = 0; i < propNames.Length; i++)
            {
                string propName = propNames[i];
                System.Object value = (System.Object)values[i];
                Debug.Log("Propname: " + propName + " value: " + values[i]);
            }
        }
    }

If you need a complete unity project with files and scripts, I can provide it too.

swingingtom commented 1 year ago

From the blender fbx exporter, this is use_custom_props parameter https://docs.blender.org/api/current/bpy.ops.export_scene.html

EdyJ commented 11 months ago

Thank you so much for the AssetPostProcessor example! Also, thank you for the pull request. I'll check it out, but most likely I'll just enable use_custom_props parameter internally. I can't see any reason for disabling it.

swingingtom commented 11 months ago

After asking the request, I felt guilty for not even trying to dive into the source, and I had many excuses, you know, never write python before, that's not my library, not aware of blender plugins, whatever...

But at the end, I manage to, and that was pretty satisfying :)