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:
Exporting from Editor (right-click on mesh asset, Asset Actions > Export… select GLTF format)
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
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.)
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…
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