RealDocs

UBlueprintPathsLibrary::MakePathRelativeTo

function Engine Blueprint Since unknown
#include "Kismet/BlueprintPathsLibrary.h"
Access: public Specifiers: staticBlueprintPure

Description

Rewrites InPath so that it is expressed relative to InRelativeTo, assuming both paths share the same base directory.

Caveats & Gotchas

  • Both paths must be relative to the same base directory (or both absolute) — mixing a relative and an absolute path gives wrong results.
  • Returns false if the conversion couldn't be performed, but OutPath may still have been written to in that case, so check the return value.
  • InRelativeTo is typically a directory, not a file; passing a file path as the base produces an off-by-one-directory result.

Signature

static ENGINE_API bool MakePathRelativeTo(const FString& InPath, const FString& InRelativeTo, FString& OutPath);

Parameters

Name Type Description Default
InPath const FString& Path to convert to be relative to InRelativeTo.
InRelativeTo const FString& Path to use as the new relative base.
OutPath FString& Receives InPath rewritten relative to InRelativeTo.

Return Type

bool

Example

Make an asset path relative to the content directory C++
FString AssetPath = TEXT("/Game/Project/Content/Meshes/Rock.uasset");
FString BaseDir = TEXT("/Game/Project/Content/");
FString RelativePath;
bool bChanged = UBlueprintPathsLibrary::MakePathRelativeTo(AssetPath, BaseDir, RelativePath);
// RelativePath == "Meshes/Rock.uasset"

Version History

Introduced in: unknown

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.