Is there really no way to preserve dict key order?

   177   2   1
User Avatar
Member
69 posts
Joined: April 2019
Offline
Hi,

I have a workflow involving exporting FBX animations to Unreal Engine with custom attributes (animation curves).

Unreal Engine imports these curves in the order they are listed on the fbx_custom_attributes point attribute, and the order is important for my workflow.

The problem is that the fbx_custom_attributes attribute is a dict type and even though I am adding the keys/values in the order I need, they always get scrambled.

In the image below, the list on the left is the order I need to keys to be in and on the right is the order they end up in.



Is there really no way to preserve the order of the keys in a dict attribute?

Thanks
Peter
Edited by mrpdean - yesterday 09:32:46

Attachments:
dict_key_order.jpg (58.4 KB)

User Avatar
Member
300 posts
Joined: Jan. 2013
Offline
A dictionary is an associative data structure meaning that the keys will always be sorted in alphabetical order. You can export together with the dictionary a list of keys ordered in a certain way and use them as keys in UE.

s[]@keys = {"DMH_jawOpen", "DMH_jawOpenFull", "DMH_jawLeft", "DMH_jawRight", 
               "DMH_jawFwd", "DMH_jawBack"};
              
d@map = set("DMH_jawOpen", 0, "DMH_jawOpenFull", 0, "DMH_jawLeft", 0, "DMH_jawRight", 0,
            "DMH_jawFwd", 0, "DMH_jawBack", 0);

i@value = @map[@keys[0]];

Another ugly way to order the keys in an array is simply by giving them a prefixed increasing value, but in UE you have to remove or skip this prefix.

d@map = set("1_DMH_jawOpen", 0, "2_DMH_jawOpenFull", 0, "3_DMH_jawLeft", 0, "4_DMH_jawRight", 0,
            "5_DMH_jawFwd", 0, "6_DMH_jawBack", 0);
User Avatar
Member
69 posts
Joined: April 2019
Offline
Thank you for clarifying that.

I suppose if the order of the keys is at least deterministic, which is sounds like it is, I should be able to come up with a workaround.

My OCD won't like it being out of sequence, but at least it should work

Thanks again.
Peter
  • Quick Links