
void CreateAnchorCallback(EOculusXRAnchorResult::Type Result, UOculusXRAnchorComponent* Anchor)
{
UE_LOG(LogTemp, Log, TEXT("Result: %s"), *UEnum::GetValueAsString(Result));
}
// Somewhere else in the code
EOculusXRAnchorResult::Type OutResult;
OculusXRAnchors::FOculusXRAnchors::CreateSpatialAnchor(
TargetActor->GetActorTransform(),
TargetActor,
FOculusXRSpatialAnchorCreateDelegate::CreateRaw(SomePointer, &SomeClass::CreateAnchorCallback),
OutResult);
SaveAnchor or SaveAnchorList. You can query saved anchors by providing a list of anchor UUIDs.
EraseAnchor() only supports locally saved anchors. The implementation explicitly checks that the anchor is stored at EOculusXRSpaceStorageLocation::Local and rejects non-local anchors.
Local or Cloud.
Local or Cloud.
Local or Cloud.
OculusXRAnchors header file. Each asynchronous function that is part of the interface takes a delegate parameter and an EOculusXRAnchorResult::Type output parameter. The delegate includes a result parameter as its first argument which represents the success or failure state of that call. The following table lists each delegate and their associated parameters.| Delegate | Parameters |
|---|---|
FOculusXRSpatialAnchorCreateDelegate | EOculusXRAnchorResult::Type ResultUOculusXRAnchorComponent* Anchor |
FOculusXRAnchorEraseDelegate | EOculusXRAnchorResult::Type ResultFOculusXRUUID AnchorUUID |
FOculusXRAnchorSaveDelegate | EOculusXRAnchorResult::Type ResultUOculusXRAnchorComponent* Anchor |
FOculusXRAnchorSaveListDelegate | EOculusXRAnchorResult::Type Resultconst TArray<UOculusXRAnchorComponent*>& SavedAnchors |
FOculusXRAnchorQueryDelegate | EOculusXRAnchorResult::Type Resultconst TArray<FOculusXRSpaceQueryResult>& Results |
OculusXRAnchors::FOculusXRAnchors::CreateSpatialAnchor and pass the anchor transform, actor, result delegate, and output result in as parameters.
AActor* NewActor = GetWorld()->SpawnActor<AActor>();
EOculusXRAnchorResult::Type OutResult;
OculusXRAnchors::FOculusXRAnchors::CreateSpatialAnchor(NewActor->GetActorTransform(),
NewActor,
FOculusXRSpatialAnchorCreateDelegate::CreateLambda([](EOculusXRAnchorResult::Type Result,
UOculusXRAnchorComponent* AnchorComponent)
{
// Post-create logic in here
}),
OutResult
);
OculusXRAnchors::FOculusXRAnchors::EraseAnchor and pass the anchor component, result delegate, and output result in as parameters.UOculusXRAnchorComponent* AnchorComponent = ...; // Retrieve anchor
EOculusXRAnchorResult::Type OutResult;
OculusXRAnchors::FOculusXRAnchors::EraseAnchor(AnchorComponent,
FOculusXRAnchorEraseDelegate::CreateLambda([](EOculusXRAnchorResult::Type Result,
FOculusXRUUID UUID)
{
// Post-erase logic here
}),
OutResult
);
OculusXRAnchors::FOculusXRAnchors::SaveAnchor and pass the anchor component, storage location, result delegate, and output result in as parameters.AnchorComponent is only valid in the case of success.UOculusXRAnchorComponent* AnchorComponent = ...; // Retrieve anchor
EOculusXRAnchorResult::Type OutResult;
OculusXRAnchors::FOculusXRAnchors::SaveAnchor(AnchorComponent,
EOculusXRSpaceStorageLocation::Local,
FOculusXRAnchorSaveDelegate::CreateLambda([](EOculusXRAnchorResult::Type Result,
UOculusXRAnchorComponent* AnchorComponent)
{
// Post-save logic here
}),
OutResult
);
OculusXRAnchors::FOculusXRAnchors::SaveAnchorList and pass the array of anchor components, storage location, result delegate, and output result in as parameters.SavedAnchors array is only valid in the case of success.TArray<UOculusXRAnchorComponent*> AnchorComponents = ...; // Retrieve anchors
EOculusXRAnchorResult::Type OutResult;
OculusXRAnchors::FOculusXRAnchors::SaveAnchorList(AnchorComponents,
EOculusXRSpaceStorageLocation::Local,
FOculusXRAnchorSaveListDelegate::CreateLambda([](EOculusXRAnchorResult::Type Result,
const TArray<UOculusXRAnchorComponent*>& SavedAnchors)
{
// Post-save logic here
}),
OutResult
);
OculusXRAnchors::FOculusXRAnchors::QueryAnchors and pass the list of UUIDs, the query location, the result delegate, and the output result in as parameters.UOculusXRAnchorBPFunctionLibrary::SpawnActorWithAnchorQueryResults.EOculusXRSpaceStorageLocation QueryLocation = EOculusXRSpaceStorageLocation::Local;
TArray<FOculusXRUUID> AnchorUUIDs = ...;
EOculusXRAnchorResult::Type OutResult;
OculusXRAnchors::FOculusXRAnchors::QueryAnchors(AnchorUUIDs, QueryLocation,
FOculusXRAnchorQueryDelegate::CreateLambda([this](EOculusXRAnchorResult::Type Result,
const TArray<FOculusXRSpaceQueryResult>& Results)
{
if (Result == EOculusXRAnchorResult::Success)
{
for (auto& it : Results)
{
UOculusXRAnchorBPFunctionLibrary::SpawnActorWithAnchorQueryResults(
GetWorld(),
it,
AActor::StaticClass(), // Your class here
Owner,
Instigator,
CollisionHandlingMethod
);
}
}
}),
OutResult
);
DiscoverAnchors is a newer API for finding anchors, providing streaming results as they are discovered. QueryAnchors remains available for UUID-based lookups.EOculusXRAnchorResult enum. Most enumeration results are general, but there are specific enumerations available for spatial anchors.UENUM(BlueprintType)
namespace EOculusXRAnchorResult
{
enum Type
{
Success,
/// Failure
Failure,
Failure_InvalidParameter,
Failure_NotInitialized,
Failure_InvalidOperation,
Failure_Unsupported,
Failure_NotYetImplemented,
Failure_OperationFailed,
Failure_InsufficientSize,
Failure_DataIsInvalid,
Failure_DeprecatedOperation,
Failure_ErrorLimitReached,
Failure_ErrorInitializationFailed,
/// Space error cases
Failure_SpaceCloudStorageDisabled,
Failure_SpaceMappingInsufficient,
Failure_SpaceLocalizationFailed,
Failure_SpaceNetworkTimeout,
Failure_SpaceNetworkRequestFailed,
Failure_SpaceInsufficientResources,
Failure_SpaceStorageAtCapacity,
Failure_SpaceInsufficientView,
Failure_SpacePermissionInsufficient,
Failure_SpaceRateLimited,
Failure_SpaceTooDark,
Failure_SpaceTooBright,
/// Warning
Warning_BoundaryVisibilitySuppressionNotAllowed,
};
}
Failure_SpaceCloudStorageDisabled: Saving anchors to cloud storage is not permitted by the user.Failure_SpaceMappingInsufficient: The user did not move around enough for a reliable localization. The user should walk and look around their space before calling save again. For example, the user could walk in a large circle around the center of their playspace.Failure_SpaceLocalizationFailed: The system failed to localize the shared anchor. This could be because the shared anchor is not near the user when calling Query.Failure_SpaceNetworkTimeout: Network operation timed out.Failure_SpaceNetworkRequestFailed: Network operation failed.Failure_SpaceInsufficientResources: System ran out of resources for spatial anchors.Failure_SpaceStorageAtCapacity: Anchor storage has reached its capacity.Failure_SpaceInsufficientView: The system does not have a sufficient view of the environment.Failure_SpacePermissionInsufficient: The app does not have sufficient permissions.Failure_SpaceRateLimited: The spatial anchor request was rate limited.Failure_SpaceTooDark: The environment is too dark for spatial anchors.Failure_SpaceTooBright: The environment is too bright for spatial anchors.Warning_BoundaryVisibilitySuppressionNotAllowed: Boundary visibility suppression is not allowed.

| Binding | Latent Action |
|---|---|
Create Spatial Anchor | OculusXR Async Create Spatial Anchor |
Erase Spatial Anchor | OculusXR Async Erase Anchor |
Save Spatial Anchor | OculusXR Async Save Anchor |
Query All Local Spatial Anchors | OculusXR Async Query Anchors |