How to use the USD API in C++?

Hello, I’m trying to create a plugin that uses the USD API to parse USD files.

I created an UE5.4.4 C++ Project and added the “USD Importer” plugin.
Then I create my plugin (named USD_Plugin).

From what I read online, I need to add “USDImporter” and “UnrealUSDWrapper” in the public module dependencies of the plugin (something like this):

public class USD_Plugin : ModuleRules
{
	public USD_Plugin(ReadOnlyTargetRules Target) : base(Target)
	{
		PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;			
		
		PublicDependencyModuleNames.AddRange(
			new string[]
			{
				"Core",
				"UnrealUSDWrapper", // Added this
				"USDImporter" // Added this
			}
		);
			
		
		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				"Projects",
				"InputCore",
				"EditorFramework",
				"UnrealEd",
				"ToolMenus",
				"CoreUObject",
				"Engine",
				"Slate",
				"SlateCore",
			}
		);
	}
}

After this, I should be able to include the USD headers.

But instead, I get an error saying:

1>Could not find definition for module 'USDImporter', (referenced via Target -> USD_Plugin.Build.cs)

I am using the Epic Games Launcher version of Unreal Engine 5.4.4.
This is an empty project with only the “USD Importer” plugin and the custom “USD_Plugin” plugin.

I figured this out a while ago now, but in case anyone is wondering, here is how you do it:

  1. Make sure you have the USDImporter plugin activated for your project.
  2. Inside your uplugin or uproject file, the following code:
"EnabledModules": [
	{
		"Name": "UnrealUSDWrapper"
	}
],
"Plugins": [
	{
		"Name": "USDImporter",
		"Enabled": true
	}
]
  1. Inside your Build.cs file, add the following lines of code:
PublicIncludePaths.AddRange(
	new string[] {
		Path.Combine(EngineDirectory, "Plugins", "Importers", "USDImporter", "Source", "ThirdParty", "USD", "include"),
    }
);

and

PublicAdditionalLibraries.AddRange(
	new string[] {
		Path.Combine(EngineDirectory, "Plugins", "Importers", "USDImporter", "Source", "ThirdParty", "USD", "lib", "usd_ANY_LIB_YOU_NEED.lib"),
	}
);

and

PublicDependencyModuleNames.AddRange(
	new string[]
	{
		// ... add other public dependencies that you statically link with here ...
		"Boost",
		"IntelTBB",
		"Python3",
    }
);
  1. Inside your source or header files, you need to wrap your USD includes using the following code:
#include "USDIncludesStart.h"
#include "pxr/pxr.h" // For example
#include "USDIncludesEnd.h"

With this, you should be able to use the USD C++ SDK as usual, though I highly recommend you take a look at the source code of USDImporter, as there are many tools to make working with USD easier.
The biggest one would be USDMemory.h that fixes a lot of memory related errors when working with USD. (There is also a wrapper for USD types, but I haven’t used it, so I cannot tell if it is good or not.)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.