How to Prevent USD Material Override Stomping?

Hello UDN,

This isn’t a bug per-se, but rather a native behavior of Unreal my team is struggling to negotiate with.

My team is working on a project that utilizes USD very heavily, creating many custom UE EUW tools to extend USD functionality in the standard UE editor.

One of our tools changes material bindings on the usd (rel material:bindings) to specific values that we need for our use case.

However, we noticed that if a USD mesh is manipulated in the scene, it triggers a call to UnrealToUsd::ConvertMeshComponent which in turn calls UnrealToUsd::ConvertMaterialOverrides. Depending on the current state of material overrides of that particular mesh, UnrealToUsd::ConvertMaterialOverrides may forcibly stomp on the value we authored to that mesh’s prim’s rel material:binding in the USD.

Is there a way to prevent the UnrealToUsd::ConvertMaterialOverrides code from running and let my project handle the management of the material overrides for a given USD mesh? It makes sense that ConvertMeshComponent needs to run, but Unreal trying to forcibly write a mesh’s material overrides everytime the material is translated/rotated/moved/etc is troublesome when we’re authoring our own material bindings to that mesh.

Any suggestions would be appreciated!

Thanks,

Henry

[Attachment Removed]

Steps to Reproduce

  1. Create a new, 5.6 project and enable the USD Importer and USD Core plugins
  2. Import any USD file that has at least one mesh in it.
  3. Set a break point on USDPrimConversion.cpp, line 3463, UnrealToUsd::ConvertMeshComponent 's last return line ‘return UnrealToUsd::ConvertMaterialOverrides(MeshAsset, MeshComponent->OverrideMaterials, UsdPrim)’
  4. In UE, change the position of the USD stage’s mesh and observe that the UnrealToUsd::ConvertMaterialOverrides line gets executed.
    [Attachment Removed]

Hi Henry,

Appreciate your patience as we recently wen through a restructuring that impacted our resposne time.

After talking with our USD team, you could author your own material overrides on a stronger USD layer, and leave the stage actor pointing at a weaker layer as its edit target. That way even if the stage actor authors a material binding to its edit target, the material binding that you author on the stronger layer should “win” and be the one visible on the viewport. It may require authoring their USD stage slightly differently though (e.g. making it so that your stage is one empty root layer where you author their custom material bindings, and have that layer use your original stage’s root layer as a sublayer).

You can see the stage’s layers on the bottom panel of the USD Stage Editor (one per row), and can right-click those rows to pick the edit target that you want for the stage actor.

From your code you can temporarily switch edit targets by using the Usd.UsdEditContext class from Python or UE::FUsdEditContex C++ wrapper if you need to, and author the material binding to the stronger layer.

[Attachment Removed]