USD runtime import not working

Trying to import a set at runtime using USD.
Works fine in editor on a “Begin Play” event.
Per the documentation:

I have added the line to my project.Target.cs:
GlobalDefinitions.Add(“FORCE_ANSI_ALLOCATOR=1”);

I have compiled my own editor, and am compiling the game with that editor, as that is the only way to get the above line to compile and link.

If I run the game within the editor, it loads the set.
If I build and run the application version of the game, it does not load the set.

Has anybody got USD loading to work at runtime, or is this something people only use in editor environments?

TIA

4 Likes

Hi @sfjohnston were you able to figure this one out? I’ve also seen your other posts about the project.target.cs, and like you was able to compile the the game successfully. I’ve tried playing around with the the different USD setter-nodes, but I haven’t been successful in getting any data in.

Can you go and have a look in your log files of your runtime application.
And see what warning error you get when you try to load the USD.

If you rebuild your project next to a source version of the engine with the global definition as defined previously it should work.

Thanks for your reply @UE_FlavienP . I think I’ve been travelling the same path as sfjohnston. Based on sparse comments on this topic, my only choice to try now is to build the engine from source.

Just for future notes:

Modifying Project.Target.cs with FORCE_ANSI_ALLOCATOR=1 yields a log error like this:

[2023.11.18-19.42.14:974][474]LogPlayLevel: UAT: CPP_001 modifies the value of GlobalDefinitions. This is not allowed, as CPP_001 has build products in common with UnrealGame.
[2023.11.18-19.42.14:985][475]LogPlayLevel: UAT: Remove the modified setting, change CPP_001 to use a unique build environment by setting 'BuildEnvironment = TargetBuildEnvironment.Unique;' in the CPP_001Target constructor, or set bOverrideBuildEnvironment = true to force this setting on.

When the instructions in the log are followed (adding the vars into Project.Target.cs), I get this error:

LogPlayLevel: UAT: Targets with a unique build environment cannot be built with an installed engine.

Which has led me to understand that I need to build the UE from scratch and I’m in fact currently doing this.

However, I don’t know if this is the only thing that I need to do? Or do I need to edit UnrealGame.Target.cs to add the FORC_ANSI_ALLOCATOR var? At any rate, I will try both the engine’s target and the project.

AFAIK you need to download the source version of the engine.
You do not need to modify the UnrealGame.Target.cs.

I think you need to:

  • add your project folder somewhere next to the Unreal “Engine” folder,
  • modify the .Target.cs file in your project to add the FORCE_ANSI_ALLOCATOR=1 settings
  • regenerate the project files so that your project is added in the solution
  • Open solution in Visual and build your project

@UE_FlavienP , thank you for verifying all those steps. Indeed, I’m happy to report that I have been able to import USD at runtime!

Just to be clear, I’d like to outline the process that I had gone through, for future reference:

  • Set up VS 2022
  • Following the instructions in this doc, I download the source, and executed the ‘setup’ and ‘generate’ scripts.
  • I opened the UE5.sln in VS, and built UE5. The docs say it might take an hour at most, but for me it lasted for 18 hours. Not sure why.
  • From VS, I ran UE5 editor (without debugger).
  • Added USD Importer plugin. Shut down editor. Ran editor again from VS.
  • In the editor, I created a C++ project, which generated the target.cs files from the get-go.
  • Added FORCE_ANSI_ALLOCATOR=1 to Project.Target.cs only.
  • Added UsdStageActor.
  • Used Level Blueprint: added UsdStageActor’s Set Root Layer node and inputted a USD file.
  • Compiled the game and saw the USD displayed.

I would like to suggest that the UE docs to mention need to build the engine from source. Without this warning, the current instruction in docs is only half true. :slight_smile:

1 Like

Hello!

Following these steps , did you manage to import USD at runtime in the editor or in a build/package?
For me it works in the editor but not in the build.

Thanks/

Try considering these options:

Explore alternative solutions like Alembic for runtime asset import, which might have better standalone support.
Investigate if there are any unofficial workarounds or community patches for USD runtime import in Unreal Engine.