// Copyright Epic Games, Inc. All Rights Reserved. #include "ARTrackableNotifyComponent.h" #include "ARBlueprintLibrary.h" #include UE_INLINE_GENERATED_CPP_BY_NAME(ARTrackableNotifyComponent) void UARTrackableNotifyComponent::OnRegister() { Super::OnRegister(); // Add the delegates we want to listen for UARBlueprintLibrary::AddOnTrackableAddedDelegate_Handle(FOnTrackableAddedDelegate::CreateUObject(this, &UARTrackableNotifyComponent::OnTrackableAdded)); UARBlueprintLibrary::AddOnTrackableUpdatedDelegate_Handle(FOnTrackableAddedDelegate::CreateUObject(this, &UARTrackableNotifyComponent::OnTrackableUpdated)); UARBlueprintLibrary::AddOnTrackableRemovedDelegate_Handle(FOnTrackableAddedDelegate::CreateUObject(this, &UARTrackableNotifyComponent::OnTrackableRemoved)); } void UARTrackableNotifyComponent::OnUnregister() { // Remove the delegates we are listening for UARBlueprintLibrary::ClearOnTrackableAddedDelegates(this); UARBlueprintLibrary::ClearOnTrackableUpdatedDelegates(this); UARBlueprintLibrary::ClearOnTrackableRemovedDelegates(this); Super::OnUnregister(); } template bool UARTrackableNotifyComponent::ConditionalDispatchEvent(UARTrackedGeometry* Tracked, DELEGATE_TYPE& Delegate) { if (OBJ_TYPE* CastObject = Cast(Tracked)) { if (Delegate.IsBound()) { Delegate.Broadcast(CastObject); } return true; } return false; } void UARTrackableNotifyComponent::OnTrackableAdded(UARTrackedGeometry* Added) { if (ConditionalDispatchEvent(Added, OnAddTrackedObject)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Added, OnAddTrackedEnvProbe)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Added, OnAddTrackedFace)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Added, OnAddTrackedImage)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Added, OnAddTrackedPoint)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Added, OnAddTrackedPlane)) { // Do nothing, since we found the right type } // Always trigger the base version since it matches all trackables if (OnAddTrackedGeometry.IsBound()) { OnAddTrackedGeometry.Broadcast(Added); } } void UARTrackableNotifyComponent::OnTrackableUpdated(UARTrackedGeometry* Updated) { if (ConditionalDispatchEvent(Updated, OnUpdateTrackedObject)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Updated, OnUpdateTrackedEnvProbe)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Updated, OnUpdateTrackedFace)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Updated, OnUpdateTrackedImage)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Updated, OnUpdateTrackedPoint)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Updated, OnUpdateTrackedPlane)) { // Do nothing, since we found the right type } // Always trigger the base version since it matches all trackables if (OnUpdateTrackedGeometry.IsBound()) { OnUpdateTrackedGeometry.Broadcast(Updated); } } void UARTrackableNotifyComponent::OnTrackableRemoved(UARTrackedGeometry* Removed) { if (ConditionalDispatchEvent(Removed, OnRemoveTrackedObject)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Removed, OnRemoveTrackedEnvProbe)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Removed, OnRemoveTrackedFace)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Removed, OnRemoveTrackedImage)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Removed, OnRemoveTrackedPoint)) { // Do nothing, since we found the right type } else if (ConditionalDispatchEvent(Removed, OnRemoveTrackedPlane)) { // Do nothing, since we found the right type } // Always trigger the base version since it matches all trackables if (OnRemoveTrackedGeometry.IsBound()) { OnRemoveTrackedGeometry.Broadcast(Removed); } }