UE5.4 blueprint to export mesh to GLTF?

GOAL: In runtime (in a build, not in the editor), export a Static Mesh to GLTF. Subsequently (after re-launch) load the exported GLTF as a static mesh.

What works for me so far:

What does not work for me yet:

  • Exporting using the ‘Export to GLTF’ blueprint node. This consistently results in a segfault dereferencing some nearly-null address. I have not yet tried to rebuild for debugging.
  • According to the documentation, all of the pins except ‘File Path’ can be left unconnected and will have sensible default behavior. This also results in a segfault.
  • I can’t set breakpoints in the plugin code (probably because I’m working with downloaded builds instead of built from source for debug) so I don’t know what invocation works in the editor, or where the blueprint version fails.
  • The documentation :wink:

If someone has a blueprint that works for them that they could share, that would be wonderful!
Another option would be guidance on using the C++ API to work with a static mesh, since I can’t find a clear example in the code.
(Otherwise, advice on how to get a debugger attached to a plugin would also be welcome.)

Thanks for reading / helping

@UE_FlavienP - it seems like you are the expert? :sweat_smile:

I’ve found where & why the crash occurs

In GLTFJsonBuilder.cpp

FGLTFJsonBuilder::FGLTFJsonBuilder(const FString& FileName, const UGLTFExportOptions* ExportOptions)
	: FGLTFFileBuilder(FileName, ExportOptions)
	, DefaultScene(JsonRoot.DefaultScene)
{
	JsonRoot.Asset.Generator = GetGeneratorString();
	if (ExportOptions->bIncludeCopyrightNotice)
	{
		JsonRoot.Asset.Copyright = GetCopyrightString();
	}
}

The crash occurs because ExportOptions == nullptr.

However, according to the blueprint node documentation a null argument should be fine.

From GLTFExporter.h

	/**
	 * Export the specified object to a glTF file (.gltf or .glb)
	 *
	 * @param Object          The object to export (supported types are UMaterialInterface, UStaticMesh, USkeletalMesh, UWorld, UAnimSequence, ULevelSequence, ULevelVariantSets). Will default to the currently active world if null.
	 * @param FilePath        The filename on disk to save as. Associated textures and binary files will be saved in the same folder, unless file extension is .glb - which results in a self-contained binary file.
	 * @param Options         The various options to use during export. Will default to the project's user-specific editor settings if null.
	 * @param SelectedActors  The set of actors to export, only applicable if the object to export is a UWorld. An empty set results in the export of all actors.
	 * @param OutMessages     The resulting log messages from the export.
	 *
	 * @return true if the object was successfully exported
	 */
	UFUNCTION(BlueprintCallable, Category = "Miscellaneous", meta=(AutoCreateRefTerm="SelectedActors"))
	static bool ExportToGLTF(UObject* Object, const FString& FilePath, const UGLTFExportOptions* Options, const TSet<AActor*>& SelectedActors, FGLTFExportMessages& OutMessages);

Reviewing the call stack there does not appear to be a point where default options are retrieved, so this looks like a bug to me.

I had previously also failed to export when options were not null, so I will try that and post again soon…

Minimal working blueprint:

Something observations:

  • Selected Actors still can be null
  • Options cannot be null, but does not need to be a persistent variable (unless you want to configure it)

NOTE: I have not been able to figure out how to make a GLTFExportOptions asset in the project, and the property-by-property configuration in a blueprint is… verbose. It would be very nice to have either:

  • A split, even if it’s huge, since defaulted values can be hidden
  • A configuration of a variable in the Editor Details view
  • Guidance on how to create and configure an asset

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