2021-09-28 13:33:17 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
# pragma once
2022-11-24 14:53:52 -05:00
# include "SmartObjectPersistentCollection.h"
2021-09-28 13:33:17 -04:00
# include "SmartObjectRuntime.h"
2022-11-17 07:44:24 -05:00
# include "WorldConditionContext.h"
2023-02-02 18:43:13 -05:00
# include "Subsystems/WorldSubsystem.h"
2023-03-02 05:58:30 -05:00
# include "AI/Navigation/NavigationTypes.h"
# include "AI/Navigation/NavQueryFilter.h"
2021-09-28 13:33:17 -04:00
# include "SmartObjectSubsystem.generated.h"
2023-01-25 02:42:36 -05:00
class UCanvas ;
class USmartObjectBehaviorDefinition ;
2021-09-28 13:33:17 -04:00
class USmartObjectComponent ;
2022-11-24 14:53:52 -05:00
class UWorldPartitionSmartObjectCollectionBuilder ;
2022-08-12 07:56:27 -04:00
struct FMassEntityManager ;
2022-02-21 01:10:34 -05:00
class ASmartObjectSubsystemRenderingActor ;
class FDebugRenderSceneProxy ;
2022-11-24 14:53:52 -05:00
class ADEPRECATED_SmartObjectCollection ;
2023-03-02 05:58:30 -05:00
class UNavigationQueryFilter ;
class ANavigationData ;
2023-08-10 07:02:20 -04:00
struct FSmartObjectValidationContext ;
2023-09-05 16:59:33 -04:00
struct FTargetingRequestHandle ;
2021-09-28 13:33:17 -04:00
2021-11-03 15:46:53 -04:00
# if WITH_EDITOR
2022-02-25 14:18:42 -05:00
/** Called when an event related to the main collection occured. */
DECLARE_MULTICAST_DELEGATE ( FOnMainCollectionEvent ) ;
2021-11-03 15:46:53 -04:00
# endif
2021-09-28 13:33:17 -04:00
/**
* Struct that can be used to filter results of a smart object request when trying to find or claim a smart object
*/
2021-11-22 16:32:17 -05:00
USTRUCT ( BlueprintType )
2021-09-28 13:33:17 -04:00
struct SMARTOBJECTSMODULE_API FSmartObjectRequestFilter
{
2021-11-22 16:32:17 -05:00
GENERATED_BODY ( )
2022-09-08 19:27:10 -04:00
// Macro needed to avoid deprecation errors with BehaviorDefinitionClass_DEPRECATED being copied or created in the default methods
PRAGMA_DISABLE_DEPRECATION_WARNINGS
2021-09-28 13:33:17 -04:00
FSmartObjectRequestFilter ( ) = default ;
2022-09-08 19:27:10 -04:00
FSmartObjectRequestFilter ( const FSmartObjectRequestFilter & ) = default ;
FSmartObjectRequestFilter ( FSmartObjectRequestFilter & & ) = default ;
FSmartObjectRequestFilter & operator = ( const FSmartObjectRequestFilter & ) = default ;
FSmartObjectRequestFilter & operator = ( FSmartObjectRequestFilter & & ) = default ;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
2021-09-28 13:33:17 -04:00
2022-11-17 07:44:24 -05:00
/** Pointer to the Actor requesting the Smart Object slot (Optional). */
2023-02-02 18:43:13 -05:00
UE_DEPRECATED ( 5.3 , " User actor is no longer provided by the request filter. Instead you must provide user data struct to claim find objects or use filter methods. " )
2022-11-17 07:44:24 -05:00
UPROPERTY ( Transient )
TObjectPtr < AActor > UserActor = nullptr ;
/** Gameplay tags of the Actor or Entity requesting the Smart Object slot. */
2021-11-22 16:32:17 -05:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = SmartObject )
2021-09-28 13:33:17 -04:00
FGameplayTagContainer UserTags ;
2021-11-22 16:32:17 -05:00
2023-11-30 02:26:33 -05:00
/** The user's claim priority. The search will contain already claimed slots at lower priority. */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = SmartObject )
ESmartObjectClaimPriority ClaimPriority = ESmartObjectClaimPriority : : Normal ;
2022-11-17 07:44:24 -05:00
/** Only return slots whose activity tags are matching this query. */
2021-11-22 16:32:17 -05:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = SmartObject )
2021-09-28 13:33:17 -04:00
FGameplayTagQuery ActivityRequirements ;
2021-11-22 16:32:17 -05:00
2022-09-08 19:27:10 -04:00
UE_DEPRECATED ( 5.1 , " Use BehaviorDefinitionClasses instead. " )
UPROPERTY ( meta = ( DeprecatedProperty , DeprecationMessage = " Use BehaviorDefinitionClasses instead " ) )
2022-09-08 19:36:03 -04:00
TSubclassOf < USmartObjectBehaviorDefinition > BehaviorDefinitionClass ;
2022-09-08 19:27:10 -04:00
2022-11-17 07:44:24 -05:00
/** If set, will filter out any SmartObject that uses different BehaviorDefinition classes. */
2021-11-22 16:32:17 -05:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = SmartObject )
2022-09-08 19:27:10 -04:00
TArray < TSubclassOf < USmartObjectBehaviorDefinition > > BehaviorDefinitionClasses ;
2021-09-28 13:33:17 -04:00
2023-03-22 08:23:20 -04:00
/** If true will evaluate the slot and object conditions, otherwise will skip them. */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = SmartObject )
bool bShouldEvaluateConditions = true ;
2023-06-29 17:44:56 -04:00
/** If true, this search will contain claimed slots. */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = SmartObject )
bool bShouldIncludeClaimedSlots = false ;
/** If true, this search will contain disabled slots. */
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = SmartObject )
bool bShouldIncludeDisabledSlots = false ;
2022-11-17 07:44:24 -05:00
/** Is set, will filter out any SmartObject that does not pass the predicate. */
2022-01-19 14:16:16 -05:00
TFunction < bool ( FSmartObjectHandle ) > Predicate ;
2022-11-17 07:44:24 -05:00
/**
* If set , will pass the context data for the selection preconditions .
* Any SmartObject that has selection preconditions but does not match the schema set the in the context data will be skipped .
*/
2023-02-02 18:43:13 -05:00
UE_DEPRECATED ( 5.3 , " Condition context data is no longer provided by the request filter. Instead you must provide user data struct to find objects or use filter methods. " )
2022-11-17 07:44:24 -05:00
FWorldConditionContextData ConditionContextData ;
2021-09-28 13:33:17 -04:00
} ;
/**
* Struct used to find a smart object within a specific search range and with optional filtering
*/
2021-11-22 16:32:17 -05:00
USTRUCT ( BlueprintType )
2021-09-28 13:33:17 -04:00
struct SMARTOBJECTSMODULE_API FSmartObjectRequest
{
2021-11-22 16:32:17 -05:00
GENERATED_BODY ( )
FSmartObjectRequest ( ) = default ;
2021-09-28 13:33:17 -04:00
FSmartObjectRequest ( const FBox & InQueryBox , const FSmartObjectRequestFilter & InFilter )
: QueryBox ( InQueryBox )
, Filter ( InFilter )
{ }
/** Box defining the search range */
2021-11-22 16:32:17 -05:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = SmartObject )
FBox QueryBox = FBox ( ForceInitToZero ) ;
2021-09-28 13:33:17 -04:00
/** Struct used to filter out some results (all results allowed by default) */
2021-11-22 16:32:17 -05:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = SmartObject )
2021-09-28 13:33:17 -04:00
FSmartObjectRequestFilter Filter ;
} ;
/**
* Struct that holds the object and slot selected by processing a smart object request .
*/
2021-11-22 16:32:17 -05:00
USTRUCT ( BlueprintType )
2021-09-28 13:33:17 -04:00
struct SMARTOBJECTSMODULE_API FSmartObjectRequestResult
{
2021-11-22 16:32:17 -05:00
GENERATED_BODY ( )
2022-03-17 19:07:54 -04:00
explicit FSmartObjectRequestResult ( const FSmartObjectHandle InSmartObjectHandle , const FSmartObjectSlotHandle InSlotHandle = { } )
2022-01-19 14:16:16 -05:00
: SmartObjectHandle ( InSmartObjectHandle )
, SlotHandle ( InSlotHandle )
2021-09-28 13:33:17 -04:00
{ }
FSmartObjectRequestResult ( ) = default ;
2022-01-19 14:16:16 -05:00
bool IsValid ( ) const { return SmartObjectHandle . IsValid ( ) & & SlotHandle . IsValid ( ) ; }
2021-09-28 13:33:17 -04:00
2021-11-22 16:32:17 -05:00
bool operator = = ( const FSmartObjectRequestResult & Other ) const
{
2022-03-18 12:31:49 -04:00
return SmartObjectHandle = = Other . SmartObjectHandle
2022-01-19 14:16:16 -05:00
& & SlotHandle = = Other . SlotHandle ;
2021-11-22 16:32:17 -05:00
}
bool operator ! = ( const FSmartObjectRequestResult & Other ) const
{
return ! ( * this = = Other ) ;
}
2022-01-19 14:16:16 -05:00
friend FString LexToString ( const FSmartObjectRequestResult & Result )
2021-09-28 13:33:17 -04:00
{
2022-01-19 14:16:16 -05:00
return FString : : Printf ( TEXT ( " Object:%s Slot:%s " ) , * LexToString ( Result . SmartObjectHandle ) , * LexToString ( Result . SlotHandle ) ) ;
2021-09-28 13:33:17 -04:00
}
2022-01-19 14:16:16 -05:00
UPROPERTY ( Transient , VisibleAnywhere , BlueprintReadOnly , Category = SmartObject )
FSmartObjectHandle SmartObjectHandle ;
2021-11-22 16:32:17 -05:00
2023-06-08 10:34:40 -04:00
UPROPERTY ( Transient , VisibleAnywhere , BlueprintReadOnly , Category = SmartObject )
2022-01-19 14:16:16 -05:00
FSmartObjectSlotHandle SlotHandle ;
2021-09-28 13:33:17 -04:00
} ;
2023-03-02 05:58:30 -05:00
/**
* Defines method for selecting slot entry from multiple candidates .
*/
UENUM ( )
enum class FSmartObjectSlotEntrySelectionMethod : uint8
{
/** Return first entry location (in order defined in the slot definition). */
First ,
/** Return nearest entry to specified search location. */
NearestToSearchLocation ,
} ;
2023-03-17 07:41:24 -04:00
/**
* Handle describing a specific entrance on a Smart Object slot .
*/
2023-04-25 08:35:21 -04:00
USTRUCT ( BlueprintType )
2023-03-17 07:41:24 -04:00
struct SMARTOBJECTSMODULE_API FSmartObjectSlotEntranceHandle
{
GENERATED_BODY ( )
FSmartObjectSlotEntranceHandle ( ) = default ;
FSmartObjectSlotHandle GetSlotHandle ( ) const { return SlotHandle ; }
bool IsValid ( ) const { return Type ! = EType : : Invalid ; }
2023-03-22 08:23:20 -04:00
bool operator = = ( const FSmartObjectSlotEntranceHandle & Other ) const
{
return SlotHandle = = Other . SlotHandle & & Type = = Other . Type & & Index = = Other . Index ;
}
bool operator ! = ( const FSmartObjectSlotEntranceHandle & Other ) const
{
return ! ( * this = = Other ) ;
}
2023-03-17 07:41:24 -04:00
private :
enum class EType : uint8
{
Invalid , // Handle is invalid
Entrance , // The handle points to a specific entrance, index is slot data index.
Slot , // The handle points to the slot itself.
} ;
2023-09-14 15:23:22 -04:00
explicit FSmartObjectSlotEntranceHandle ( const FSmartObjectSlotHandle InSlotHandle , const EType InType , const int32 InIndex = 0 )
2023-03-17 07:41:24 -04:00
: SlotHandle ( InSlotHandle )
, Type ( InType )
{
2023-09-14 15:23:22 -04:00
using IndexType = decltype ( Index ) ;
check ( InIndex > = std : : numeric_limits < IndexType > : : min ( ) & & InIndex < = std : : numeric_limits < IndexType > : : max ( ) ) ;
Index = static_cast < IndexType > ( InIndex ) ;
2023-03-17 07:41:24 -04:00
}
2023-04-25 08:35:21 -04:00
UPROPERTY ( VisibleAnywhere , BlueprintReadOnly , Category = " SmartObject " , meta = ( AllowPrivateAccess = " true " ) )
2023-03-17 07:41:24 -04:00
FSmartObjectSlotHandle SlotHandle ;
EType Type = EType : : Invalid ;
uint8 Index = 0 ;
friend class USmartObjectSubsystem ;
} ;
2023-03-14 06:26:29 -04:00
/**
* Struct used to request slot entry or exit location .
*
2023-03-27 08:22:19 -04:00
* When used with actor , it is generally enough to set the UserActor . In that case NavigationData , ValidationFilter ,
* and UserCapsule are queried via the INavAgentInterface and USmartObjectUserComponent on the actor if they are _not_ set .
*
* If the user actor is not available ( e . g . with Mass ) , then ValidationFilter and UserCapsule must be defined , and if bProjectNavigationLocation is set NavigationData must be valid .
*
2023-03-14 06:26:29 -04:00
* The location validation is done in following order :
* - navigation projection
* - trace ground location ( uses altered location from navigation test if applicable )
* - check transition trajectory ( test between unmodified navigation location and slow location )
2023-03-02 05:58:30 -05:00
*/
2023-08-10 07:02:20 -04:00
USTRUCT ( BlueprintType )
2023-03-14 06:26:29 -04:00
struct SMARTOBJECTSMODULE_API FSmartObjectSlotEntranceLocationRequest
2023-03-02 05:58:30 -05:00
{
GENERATED_BODY ( )
2023-08-10 07:02:20 -04:00
// Macro needed to avoid deprecation errors with "UserCapsule" being copied or created in the default methods
PRAGMA_DISABLE_DEPRECATION_WARNINGS
FSmartObjectSlotEntranceLocationRequest ( ) = default ;
FSmartObjectSlotEntranceLocationRequest ( const FSmartObjectSlotEntranceLocationRequest & ) = default ;
FSmartObjectSlotEntranceLocationRequest ( FSmartObjectSlotEntranceLocationRequest & & ) = default ;
FSmartObjectSlotEntranceLocationRequest & operator = ( const FSmartObjectSlotEntranceLocationRequest & ) = default ;
FSmartObjectSlotEntranceLocationRequest & operator = ( FSmartObjectSlotEntranceLocationRequest & & ) = default ;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
2023-03-27 08:22:19 -04:00
/** Actor that is using the smart object slot. (Optional) */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
2023-03-27 08:22:19 -04:00
TObjectPtr < const AActor > UserActor = nullptr ;
2023-03-02 05:58:30 -05:00
2023-03-27 08:22:19 -04:00
/** Filter to use for the validation. If not set and UserActor is valid, the filter is queried via USmartObjectUserComponent. */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
2023-03-14 06:26:29 -04:00
TSubclassOf < USmartObjectSlotValidationFilter > ValidationFilter = nullptr ;
2023-03-27 08:22:19 -04:00
/** Navigation data to use for the navigation queries. If not set and UserActor is valid, the navigation data is queried via INavAgentInterface. */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
2023-03-27 08:22:19 -04:00
TObjectPtr < const ANavigationData > NavigationData = nullptr ;
/** Size of the user of the smart object. If not set and UserActor is valid, the dimensions are queried via INavAgentInterface. */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
FSmartObjectUserCapsuleParams UserCapsuleParams = FSmartObjectUserCapsuleParams : : Invalid ;
2023-03-27 08:22:19 -04:00
/** Search location that may be used to select an entry from multiple candidates. (e.g. user actor location). */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
2023-03-14 06:26:29 -04:00
FVector SearchLocation = FVector : : ZeroVector ;
2023-03-02 05:58:30 -05:00
/** How to select an entry when a slot has multiple entries. */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
2023-03-02 05:58:30 -05:00
FSmartObjectSlotEntrySelectionMethod SelectMethod = FSmartObjectSlotEntrySelectionMethod : : First ;
2023-03-14 06:26:29 -04:00
/** Enum indicating if we're looking for a location to enter or exit the Smart Object slot. */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
2023-03-14 06:26:29 -04:00
ESmartObjectSlotNavigationLocationType LocationType = ESmartObjectSlotNavigationLocationType : : Entry ;
2023-03-02 05:58:30 -05:00
2023-03-14 06:26:29 -04:00
/** If true, try to project the location on navigable area. If projection fails, an entry is discarded. */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
2023-03-14 06:26:29 -04:00
bool bProjectNavigationLocation = true ;
/** If true, try to trace the location on ground. If trace fails, an entry is discarded. */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
2023-03-14 06:26:29 -04:00
bool bTraceGroundLocation = true ;
/** If true, check collisions between navigation location and slot location. If collisions are found, an entry is discarded. */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
2023-03-14 06:26:29 -04:00
bool bCheckTransitionTrajectory = true ;
2023-03-21 07:37:13 -04:00
/** If true, check user capsule collisions at the entrance location. Uses capsule dimensions set in the validation filter. */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
2023-03-21 07:37:13 -04:00
bool bCheckEntranceLocationOverlap = true ;
/** If true, check user capsule collisions at the slot location. Uses capsule dimensions set in an annotation on the slot. */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
2023-03-21 07:37:13 -04:00
bool bCheckSlotLocationOverlap = true ;
2023-03-14 06:26:29 -04:00
/** If true, include slot location as a candidate if no navigation annotation is present. */
2023-08-10 07:02:20 -04:00
UPROPERTY ( EditAnywhere , BlueprintReadWrite , Category = " SmartObject " )
2023-03-02 05:58:30 -05:00
bool bUseSlotLocationAsFallback = false ;
2023-08-10 07:02:20 -04:00
UE_DEPRECATED ( 5.4 , " Use UserCapsuleParams instead. " )
TOptional < FSmartObjectUserCapsuleParams > UserCapsule ;
2023-03-02 05:58:30 -05:00
} ;
/**
2023-03-17 07:41:24 -04:00
* Validated result from FindEntranceLocationForSlot ( ) .
2023-03-02 05:58:30 -05:00
*/
2023-04-25 08:35:21 -04:00
USTRUCT ( BlueprintType )
2023-03-17 07:41:24 -04:00
struct SMARTOBJECTSMODULE_API FSmartObjectSlotEntranceLocationResult
2023-03-02 05:58:30 -05:00
{
GENERATED_BODY ( )
2023-06-06 09:07:47 -04:00
// Macro needed to avoid deprecation errors with "Tag" being copied or created in the default methods
PRAGMA_DISABLE_DEPRECATION_WARNINGS
FSmartObjectSlotEntranceLocationResult ( ) = default ;
FSmartObjectSlotEntranceLocationResult ( const FSmartObjectSlotEntranceLocationResult & ) = default ;
FSmartObjectSlotEntranceLocationResult ( FSmartObjectSlotEntranceLocationResult & & ) = default ;
FSmartObjectSlotEntranceLocationResult & operator = ( const FSmartObjectSlotEntranceLocationResult & ) = default ;
FSmartObjectSlotEntranceLocationResult & operator = ( FSmartObjectSlotEntranceLocationResult & & ) = default ;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
2023-03-02 05:58:30 -05:00
/** @returns entry as nav location. */
FNavLocation GetNavLocation ( ) const { return FNavLocation ( Location , NodeRef ) ; }
/** @returns true if the result contains valid navigation node reference. */
bool HasNodeRef ( ) const { return NodeRef ! = INVALID_NAVNODEREF ; }
2023-03-14 06:26:29 -04:00
/** The location to enter the slot. */
2023-04-25 08:35:21 -04:00
UPROPERTY ( VisibleAnywhere , BlueprintReadOnly , Category = " SmartObject " )
2023-03-02 05:58:30 -05:00
FVector Location = FVector : : ZeroVector ;
2023-03-14 06:26:29 -04:00
/** The expected direction to enter the slot. */
2023-04-25 08:35:21 -04:00
UPROPERTY ( VisibleAnywhere , BlueprintReadOnly , Category = " SmartObject " )
2023-03-02 05:58:30 -05:00
FRotator Rotation = FRotator : : ZeroRotator ;
/** Node reference in navigation data (if requested with bMustBeNavigable). */
NavNodeRef NodeRef = INVALID_NAVNODEREF ;
2023-06-06 09:07:47 -04:00
/** Gameplay tag associated with the entrance. */
UE_DEPRECATED ( 5.3 , " Use Tags instead. " )
2023-08-10 07:02:20 -04:00
UPROPERTY ( )
2023-03-02 05:58:30 -05:00
FGameplayTag Tag ;
2023-03-17 07:41:24 -04:00
2023-06-06 09:07:47 -04:00
/** Gameplay tags associated with the entrance. */
UPROPERTY ( VisibleAnywhere , BlueprintReadOnly , Category = " SmartObject " )
FGameplayTagContainer Tags ;
2023-03-17 07:41:24 -04:00
/** Handle identifying the entrance that was found. */
2023-04-25 08:35:21 -04:00
UPROPERTY ( VisibleAnywhere , BlueprintReadOnly , Category = " SmartObject " )
2023-03-17 07:41:24 -04:00
FSmartObjectSlotEntranceHandle EntranceHandle ;
2023-08-10 07:02:20 -04:00
/** True if the result has passed validation tests. */
UPROPERTY ( VisibleAnywhere , BlueprintReadOnly , Category = " SmartObject " )
bool bIsValid = true ;
2023-03-02 05:58:30 -05:00
} ;
2023-03-17 07:41:24 -04:00
using FSmartObjectSlotNavigationLocationResult = FSmartObjectSlotEntranceLocationResult ;
2022-01-12 16:15:32 -05:00
/**
* Result code indicating if the Collection was successfully registered or why it was not .
*/
UENUM ( )
2022-03-02 13:25:37 -05:00
enum class ESmartObjectCollectionRegistrationResult : uint8
2022-01-12 16:15:32 -05:00
{
Failed_InvalidCollection ,
Failed_AlreadyRegistered ,
Failed_NotFromPersistentLevel ,
2022-03-02 13:25:37 -05:00
Succeeded
2022-01-31 18:52:49 -05:00
} ;
2022-03-30 15:13:42 -04:00
/**
* Mode that indicates how the unregistration of the SmartObjectComponent affects its runtime instance .
*/
UENUM ( )
2022-12-07 13:05:23 -05:00
enum class UE_DEPRECATED ( 5.2 , " This type is deprecated and no longer being used. " ) ESmartObjectUnregistrationMode : uint8
2022-03-30 15:13:42 -04:00
{
2022-11-24 14:53:52 -05:00
KeepRuntimeInstanceActiveIfPartOfCollection ,
2022-03-30 15:13:42 -04:00
DestroyRuntimeInstance
} ;
2021-09-28 13:33:17 -04:00
/**
* Subsystem that holds all registered smart object instances and offers the API for spatial queries and reservations .
*/
2022-02-21 01:10:34 -05:00
UCLASS ( config = SmartObjects , defaultconfig , Transient )
2021-09-28 13:33:17 -04:00
class SMARTOBJECTSMODULE_API USmartObjectSubsystem : public UWorldSubsystem
{
GENERATED_BODY ( )
public :
2022-11-24 14:53:52 -05:00
USmartObjectSubsystem ( ) ;
2021-09-28 13:33:17 -04:00
static USmartObjectSubsystem * GetCurrent ( const UWorld * World ) ;
2022-11-24 14:53:52 -05:00
ESmartObjectCollectionRegistrationResult RegisterCollection ( ASmartObjectPersistentCollection & InCollection ) ;
void UnregisterCollection ( ASmartObjectPersistentCollection & InCollection ) ;
const FSmartObjectContainer & GetSmartObjectContainer ( ) const { return SmartObjectContainer ; }
FSmartObjectContainer & GetMutableSmartObjectContainer ( ) { return SmartObjectContainer ; }
2021-09-28 13:33:17 -04:00
2023-01-18 10:52:51 -05:00
/**
2023-11-29 11:23:11 -05:00
* Enables or disables the entire smart object represented by the provided handle using the default reason ( i . e . Gameplay ) . .
2023-01-18 10:52:51 -05:00
* Delegate ' OnEvent ' is broadcasted with ESmartObjectChangeReason : : OnEnabled / ESmartObjectChangeReason : : OnDisabled if state changed .
* @ param Handle Handle to the smart object .
* @ param bEnabled If true enables the smart object , disables otherwise .
* @ return True when associated smart object is found and set ( or already set ) to desired state ; false otherwise .
*/
2023-11-29 11:23:11 -05:00
UFUNCTION ( BlueprintCallable , Category = " SmartObject " , meta = ( DisplayName = " Set SmartObject Enabled (default reason: Gameplay) " , ReturnDisplayName = " Status changed " ) )
2023-01-18 10:52:51 -05:00
bool SetEnabled ( const FSmartObjectHandle Handle , const bool bEnabled ) ;
2023-02-28 10:24:32 -05:00
/**
2023-11-29 11:23:11 -05:00
* Enables or disables the entire smart object represented by the provided handle using the specified reason .
* Delegate ' OnEvent ' is broadcasted with ESmartObjectChangeReason : : OnEnabled / ESmartObjectChangeReason : : OnDisabled if state changed .
* @ param Handle Handle to the smart object .
* @ param ReasonTag Valid Tag to specify the reason for changing the enabled state of the object . Method will ensure if not valid ( i . e . None ) .
* @ param bEnabled If true enables the smart object , disables otherwise .
* @ return True when associated smart object is found and set ( or already set ) to desired state ; false otherwise .
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " , meta = ( DisplayName = " Set SmartObject Enabled (specific reason) " , ReturnDisplayName = " Status changed " ) )
bool SetEnabledForReason ( const FSmartObjectHandle Handle , FGameplayTag ReasonTag , const bool bEnabled ) ;
/**
* Returns the enabled state of the smart object represented by the provided handle regardless of the disabled reason .
2023-02-28 10:24:32 -05:00
* @ param Handle Handle to the smart object .
* @ return True when associated smart object is found and set to be enabled . False otherwise .
*/
2023-11-29 11:23:11 -05:00
UFUNCTION ( BlueprintCallable , BlueprintPure , Category = " SmartObject " , meta = ( DisplayName = " Is SmartObject Enabled (for any reason) " , ReturnDisplayName = " Enabled " ) )
2023-02-28 10:24:32 -05:00
bool IsEnabled ( const FSmartObjectHandle Handle ) const ;
2023-11-29 11:23:11 -05:00
/**
* Returns the enabled state of the smart object represented by the provided handle based on a specific reason .
* @ param Handle Handle to the smart object .
* @ param ReasonTag Valid Tag to test if enabled for a specific reason . Method will ensure if not valid ( i . e . None ) .
* @ return True when associated smart object is found and set to be enabled . False otherwise .
*/
UFUNCTION ( BlueprintCallable , BlueprintPure , Category = " SmartObject " , meta = ( DisplayName = " Is SmartObject Enabled (for specific reason) " , ReturnDisplayName = " Enabled " ) )
bool IsEnabledForReason ( const FSmartObjectHandle Handle , FGameplayTag ReasonTag ) const ;
2023-01-18 10:52:51 -05:00
/**
* Enables or disables all smart objects associated to the provided actor ( multiple components ) .
* @ param SmartObjectActor Smart object ( s ) parent actor .
* @ param bEnabled If true enables , disables otherwise .
2023-02-02 18:43:13 -05:00
* @ return True if all ( at least one ) smartobject components are found with their associated
* runtime and values set ( or already set ) to desired state ; false otherwise .
2023-01-18 10:52:51 -05:00
*/
bool SetSmartObjectActorEnabled ( const AActor & SmartObjectActor , bool bEnabled ) ;
2022-03-30 15:13:42 -04:00
/**
* Registers to the runtime simulation all SmartObject components for a given actor .
* @ param SmartObjectActor Actor owning the components to register
* @ return true when components are found and all successfully registered , false otherwise
*/
bool RegisterSmartObjectActor ( const AActor & SmartObjectActor ) ;
/**
* Unregisters from the simulation all SmartObject components for a given actor .
* @ param SmartObjectActor Actor owning the components to unregister
* @ return true when components are found and all successfully unregistered , false otherwise
*/
bool UnregisterSmartObjectActor ( const AActor & SmartObjectActor ) ;
2022-12-07 13:05:23 -05:00
/**
* Removes all data associated to SmartObject components of a given actor from the simulation .
* @ param SmartObjectActor Actor owning the components to delete
* @ return whether components are found and all successfully deleted
*/
bool RemoveSmartObjectActor ( const AActor & SmartObjectActor ) ;
2022-03-30 15:13:42 -04:00
/**
* Registers a SmartObject components to the runtime simulation .
* @ param SmartObjectComponent SmartObject component to register
* @ return true when component is successfully registered , false otherwise
*/
2021-09-28 13:33:17 -04:00
bool RegisterSmartObject ( USmartObjectComponent & SmartObjectComponent ) ;
2022-03-30 15:13:42 -04:00
/**
2023-04-18 09:40:15 -04:00
* Unbinds a SmartObject component from the runtime simulation and handles the associated runtime data
* according to the component registration type ( i . e . runtime data associated to components from persistent collections
* will remain in the simulation ) .
2022-03-30 15:13:42 -04:00
* @ param SmartObjectComponent SmartObject component to unregister
* @ return true when component is successfully unregistered , false otherwise
*/
2021-09-28 13:33:17 -04:00
bool UnregisterSmartObject ( USmartObjectComponent & SmartObjectComponent ) ;
2022-12-07 13:05:23 -05:00
/**
2023-04-18 09:40:15 -04:00
* Unbinds a SmartObject component from the runtime simulation and removes its runtime data .
2022-12-07 13:05:23 -05:00
* @ param SmartObjectComponent SmartObject component to remove
* @ return whether SmartObject data has been successfully found and removed
*/
bool RemoveSmartObject ( USmartObjectComponent & SmartObjectComponent ) ;
/**
* Binds a smartobject component to an existing instance in the simulation . If a given SmartObjectComponent has not
* been registered yet an ensure will trigger .
* @ param SmartObjectComponent The component to add to the simulation and for which a runtime instance must exist
*/
void BindComponentToSimulation ( USmartObjectComponent & SmartObjectComponent ) ;
2023-11-22 04:49:00 -05:00
/**
* Updates the smart object transform .
* @ param Handle Handle to the Smart Object to update .
* @ param NewTransform New transform of the runtime Smart Object
* @ return is transform was updated .
*/
bool UpdateSmartObjectTransform ( const FSmartObjectHandle Handle , const FTransform & NewTransform ) ;
2021-09-28 13:33:17 -04:00
/**
* Returns the component associated to the claim handle if still
* accessible . In some scenarios the component may no longer exist
* but its smart object data could ( e . g . streaming )
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
2021-09-28 13:33:17 -04:00
* @ return A pointer to the USmartObjectComponent * associated to the handle .
*/
2021-11-22 16:32:17 -05:00
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
2021-09-28 13:33:17 -04:00
USmartObjectComponent * GetSmartObjectComponent ( const FSmartObjectClaimHandle & ClaimHandle ) const ;
2022-09-12 19:23:55 -04:00
/**
* Returns the component associated to the given request result
* In some scenarios the component may no longer exist
* but its smart object data could ( e . g . streaming )
* @ param Result A request result returned by any of the Find methods .
* @ return A pointer to the USmartObjectComponent * associated to the handle .
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
USmartObjectComponent * GetSmartObjectComponentByRequestResult ( const FSmartObjectRequestResult & Result ) const ;
2021-09-28 13:33:17 -04:00
/**
2023-02-02 18:43:13 -05:00
* Spatial lookup for first slot in range respecting request criteria and selection conditions .
* @ param Request Parameters defining the search area and criteria
* @ param UserData Additional data that could be provided to bind values in the conditions evaluation context
* @ return First valid smart object in range . Not the closest one , just the one
* that happens to be retrieved first from space partition
*/
[ [ nodiscard ] ] FSmartObjectRequestResult FindSmartObject ( const FSmartObjectRequest & Request , const FConstStructView UserData ) const ;
/**
* Spatial lookup for slot candidates respecting request criteria and selection conditions .
* @ param Request Parameters defining the search area and criteria
* @ param OutResults List of smart object slot candidates found in range
* @ param UserData Additional data that could be provided to bind values in the conditions evaluation context
* @ return True if at least one candidate was found .
*/
bool FindSmartObjects ( const FSmartObjectRequest & Request , TArray < FSmartObjectRequestResult > & OutResults , const FConstStructView UserData ) const ;
2023-09-05 11:29:58 -04:00
/**
* Search list of specific actors ( often from a physics query ) for slot candidates respecting request criteria and selection conditions .
*
* @ param Filter Parameters defining the search area and criteria
* @ param ActorList Ordered list of actors to search
* @ param OutResults List of smart object slot candidates found in range
* @ param UserData Additional data that could be provided to bind values in the conditions evaluation context
* @ return True if at least one candidate was found .
*/
bool FindSmartObjectsInList ( const FSmartObjectRequestFilter & Filter , const TConstArrayView < AActor * > ActorList , TArray < FSmartObjectRequestResult > & OutResults , const FConstStructView UserData ) const ;
2023-09-05 16:59:33 -04:00
/**
* Search the results of the given targeting request handle for smart objects that match the request criteria
*
* @ param Filter Parameters defining the search area and criteria
* @ param TargetingHandle The targeting handle of the request that will have its resulted searched for smart objects
* @ param OutResults List of smart object slot candidates found in range
* @ param UserData Additional data that could be provided to bind values in the conditions evaluation context
*
* @ return True if at least one candidate was found .
*/
bool FindSmartObjectsInTargetingRequest ( const FSmartObjectRequestFilter & Filter , const FTargetingRequestHandle TargetingHandle , TArray < FSmartObjectRequestResult > & OutResults , const FConstStructView UserData ) const ;
2023-02-02 18:43:13 -05:00
/**
* Spatial lookup for first slot in range respecting request criteria and selection conditions .
* @ param Request Parameters defining the search area and criteria
* @ param UserActor Actor claiming the smart object used to evaluate selection conditions
2021-09-28 13:33:17 -04:00
* @ return First valid smart object in range . Not the closest one , just the one
2022-03-16 03:47:02 -04:00
* that happens to be retrieved first from space partition
2021-09-28 13:33:17 -04:00
*/
2021-11-22 16:32:17 -05:00
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
2023-02-02 18:43:13 -05:00
FSmartObjectRequestResult FindSmartObject ( const FSmartObjectRequest & Request , const AActor * UserActor = nullptr ) const
{
return FindSmartObject ( Request , FConstStructView : : Make ( FSmartObjectActorUserData ( UserActor ) ) ) ;
}
2021-09-28 13:33:17 -04:00
/**
2023-04-21 16:47:40 -04:00
* Spatial lookup for slot candidates respecting request criteria and selection conditions .
2023-02-02 18:43:13 -05:00
* @ param Request Parameters defining the search area and criteria
* @ param OutResults List of smart object slot candidates
* @ param UserActor Actor claiming the smart object
2021-09-28 13:33:17 -04:00
* @ return All valid smart objects in range .
*/
2023-04-21 16:47:40 -04:00
UFUNCTION ( BlueprintCallable , Category = " SmartObject " , meta = ( DisplayName = " Find Smart Objects (Pure) " , DeprecatedFunction , DeprecationMessage = " The pure version is deprecated, place a new Find Smart Objects node and connect the exec pin " ) )
2023-02-02 18:43:13 -05:00
bool FindSmartObjects ( const FSmartObjectRequest & Request , TArray < FSmartObjectRequestResult > & OutResults , const AActor * UserActor = nullptr ) const
{
return FindSmartObjects ( Request , OutResults , FConstStructView : : Make ( FSmartObjectActorUserData ( UserActor ) ) ) ;
}
2021-09-28 13:33:17 -04:00
2023-04-21 16:47:40 -04:00
/**
* Blueprint function for spatial lookup for slot candidates respecting request criteria and selection conditions .
* @ param Request Parameters defining the search area and criteria
* @ param OutResults List of smart object slot candidates
* @ param UserActor Actor claiming the smart object
* @ return All valid smart objects in range .
*/
UFUNCTION ( BlueprintCallable , BlueprintPure = False , Category = " SmartObject " , meta = ( DisplayName = " Find Smart Objects " ) )
bool FindSmartObjects_BP ( const FSmartObjectRequest & Request , TArray < FSmartObjectRequestResult > & OutResults , const AActor * UserActor = nullptr ) const
{
return FindSmartObjects ( Request , OutResults , FConstStructView : : Make ( FSmartObjectActorUserData ( UserActor ) ) ) ;
}
2022-01-31 18:52:49 -05:00
/**
* Returns slots of a given smart object matching the filter .
2022-03-18 12:31:49 -04:00
* @ param Handle Handle to the smart object .
* @ param Filter Filter to apply on object and slots .
2022-01-31 18:52:49 -05:00
* @ param OutSlots Available slots found that match the filter
2023-02-02 18:43:13 -05:00
* @ param UserData Optional additional data that could be provided to bind values in the conditions evaluation context
2022-01-31 18:52:49 -05:00
*/
2023-02-02 18:43:13 -05:00
void FindSlots ( const FSmartObjectHandle Handle , const FSmartObjectRequestFilter & Filter , TArray < FSmartObjectSlotHandle > & OutSlots , const FConstStructView UserData = { } ) const ;
2021-09-28 13:33:17 -04:00
2022-11-01 15:11:25 -04:00
/**
* Return all slots of a given smart object .
* @ param Handle Handle to the smart object .
* @ param OutSlots All slots of the smart object
*/
2023-09-05 11:29:58 -04:00
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
2022-11-01 15:11:25 -04:00
void GetAllSlots ( const FSmartObjectHandle Handle , TArray < FSmartObjectSlotHandle > & OutSlots ) const ;
2023-02-02 18:43:13 -05:00
/**
* Evaluates conditions of each slot and add to the result array on success .
* Optional user data can be provided to bind parameters in evaluation context based
* on the schema used by the object definition .
* @ param SlotsToFilter List of slot handles to apply selection conditions on
* @ param UserData Additional data that could be provided to bind values in the conditions evaluation context
* @ return List of slot handles that pass all their selection conditions
*/
[ [ nodiscard ] ] TArray < FSmartObjectSlotHandle > FilterSlotsBySelectionConditions (
const TConstArrayView < FSmartObjectSlotHandle > & SlotsToFilter ,
const FConstStructView UserData
) const ;
/**
* Evaluates conditions of the slot specified by each request result and add to the result array on success .
* Optional user data can be provided to bind parameters in evaluation context based
* on the schema used by the object definition .
* @ param ResultsToFilter List of request results to apply selection conditions on
* @ param UserData The additional data that could be bound in the conditions evaluation context
* @ return List of request results that pass all their selection conditions
*/
[ [ nodiscard ] ] TArray < FSmartObjectRequestResult > FilterResultsBySelectionConditions (
const TConstArrayView < FSmartObjectRequestResult > & ResultsToFilter ,
const FConstStructView UserData
) const ;
/**
* Evaluates conditions of the specified slot and its parent smart object .
* Optional user data can be provided to bind parameters in evaluation context based
* on the schema used by the object definition .
* @ param SlotHandle Handle to the smart object slot
* @ param UserData Additional data that could be provided to bind values in the conditions evaluation context
* @ return True if all conditions are met ; false otherwise
*/
[ [ nodiscard ] ] bool EvaluateSelectionConditions ( const FSmartObjectSlotHandle SlotHandle , const FConstStructView UserData ) const ;
2023-03-02 05:58:30 -05:00
/**
2023-03-17 07:41:24 -04:00
* Finds entrance location for a specific slot . Each slot can be annotated with multiple entrance locations , and the request can be configured to also consider the slot location as one entry .
* Additionally the entrance locations can be checked to be on navigable surface ( does not check that the point is reachable , though ) , traced on ground , and without of collisions .
2023-03-02 05:58:30 -05:00
* @ param SlotHandle Handle to the smart object slot .
* @ param Request Request describing how to select the entry .
* @ param Result Entry location result ( in world space ) .
* @ return True if valid entry found .
*/
2023-03-17 07:41:24 -04:00
bool FindEntranceLocationForSlot ( const FSmartObjectSlotHandle SlotHandle , const FSmartObjectSlotEntranceLocationRequest & Request , FSmartObjectSlotEntranceLocationResult & Result ) const ;
/**
* Runs the same logic as FindEntranceLocationForSlot ( ) but for a specific entrance location . The entrance handle can be get from entrance location result .
* @ param EntranceHandle Handle to a specific smart object slot entrance .
* @ param Request Request describing how to select the entry .
* @ param Result Entry location result ( in world space ) .
* @ return True if result is valid .
*/
bool UpdateEntranceLocation ( const FSmartObjectSlotEntranceHandle EntranceHandle , const FSmartObjectSlotEntranceLocationRequest & Request , FSmartObjectSlotEntranceLocationResult & Result ) const ;
2023-06-08 10:34:40 -04:00
2023-08-10 07:02:20 -04:00
/**
* Runs the entrance validation logic for all the slots in the Smart Object definition and returns all validated locations .
* This method can be used to a Smart Object definition before it is added to the simulation , for example to show some UI visualization while placing an actor with Smart Object .
2023-08-14 03:40:42 -04:00
* The method is static so it can be used even if the SmartObject subsystem is not present .
* @ param World World to use for validation tracing .
2023-08-10 07:02:20 -04:00
* @ param SmartObjectDefinition Smart Object definition to validate .
* @ param SmartObjectTransform World transform of the Smart Object definition ( e . g . Smart Object Component transform ) .
* @ param SkipActor An actor to skip during validation ( this could be an actor representing the Smart Object during placement ) .
* @ param Request Request describing how to validate the entries .
* @ param Results All entrance locations , FSmartObjectSlotEntranceLocationResult : : bIsValid can be used to check if a specific result is valid .
* @ return True if any entrances were found .
*/
2023-08-14 03:40:42 -04:00
static bool QueryAllValidatedEntranceLocations (
const UWorld * World ,
2023-08-10 07:02:20 -04:00
const USmartObjectDefinition & SmartObjectDefinition ,
const FTransform & SmartObjectTransform ,
const AActor * SkipActor ,
const FSmartObjectSlotEntranceLocationRequest & Request ,
TArray < FSmartObjectSlotEntranceLocationResult > & Results
2023-08-14 03:40:42 -04:00
) ;
2023-08-10 07:02:20 -04:00
2023-06-08 10:34:40 -04:00
/**
* Checks whether given slot is free and can be claimed ( i . e . slot and its parent are both enabled )
* @ note This methods doesn ' t evaluate the selection conditions . EvaluateSelectionConditions must be called separately .
2023-11-30 02:26:33 -05:00
* @ param SlotHandle Handle to a smart object slot .
* @ param ClaimPriority Claim priority , a slot claimed at lower priority can be claimed by higher priority ( unless already in use ) .
2023-06-08 10:34:40 -04:00
* @ return true if the indicated slot can be claimed , false otherwise
* @ see EvaluateSelectionConditions
*/
2023-11-30 02:26:33 -05:00
[ [ nodiscard ] ] bool CanBeClaimed ( const FSmartObjectSlotHandle SlotHandle , ESmartObjectClaimPriority ClaimPriority = ESmartObjectClaimPriority : : Normal ) const ;
2023-06-08 10:34:40 -04:00
2021-09-28 13:33:17 -04:00
/**
2022-03-18 12:31:49 -04:00
* Claims smart object from a request result .
* @ param RequestResult Request result for given smart object and slot index .
2023-02-02 18:43:13 -05:00
* @ param UserActor Actor claiming the smart object
2022-03-18 12:31:49 -04:00
* @ return A handle binding the claimed smart object , its slot and a user id .
2021-09-28 13:33:17 -04:00
*/
2023-06-08 10:34:40 -04:00
UE_DEPRECATED ( 5.3 , " Please use MarkSmartObjectSlotAsClaimed instead " )
UFUNCTION ( BlueprintCallable , Category = " SmartObject " , meta = ( DeprecatedFunction , DeprecationMessage = " Use MarkSmartObjectSlotAsClaimed instead. " ) )
2023-02-02 18:43:13 -05:00
FSmartObjectClaimHandle Claim ( const FSmartObjectRequestResult & RequestResult , const AActor * UserActor = nullptr )
{
2023-11-30 02:26:33 -05:00
return MarkSlotAsClaimed ( RequestResult . SlotHandle , ESmartObjectClaimPriority : : Normal , FConstStructView : : Make ( FSmartObjectActorUserData ( UserActor ) ) ) ;
2023-02-02 18:43:13 -05:00
}
2021-09-28 13:33:17 -04:00
2023-02-02 18:43:13 -05:00
/**
* Claim smart object slot .
* @ param SlotHandle Handle to a smart object slot .
* @ param UserData Instanced struct that represents the interacting agent .
* @ return A handle binding the claimed smart object , its slot and a user id .
*/
2023-06-08 10:34:40 -04:00
UE_DEPRECATED ( 5.3 , " Please use MarkSlotAsClaimed instead " )
[ [ nodiscard ] ] FSmartObjectClaimHandle Claim ( const FSmartObjectSlotHandle SlotHandle , const FConstStructView UserData = { } )
{
2023-11-30 02:26:33 -05:00
return MarkSlotAsClaimed ( SlotHandle , ESmartObjectClaimPriority : : Normal , UserData ) ;
2023-06-08 10:34:40 -04:00
}
2022-03-16 03:47:02 -04:00
/**
2022-03-18 12:31:49 -04:00
* Claim smart object from object and slot handles .
* @ param Handle Handle to the smart object .
* @ param SlotHandle Handle to a smart object slot .
* @ return A handle binding the claimed smart object , its slot and a user id .
2022-03-16 03:47:02 -04:00
*/
2023-06-08 10:34:40 -04:00
UE_DEPRECATED ( 5.3 , " Please use MarkSlotAsClaimed passing only the slot handle " )
[ [ nodiscard ] ] FSmartObjectClaimHandle Claim ( const FSmartObjectHandle Handle , FSmartObjectSlotHandle SlotHandle ) { return MarkSlotAsClaimed ( SlotHandle , { } ) ; }
2022-03-16 03:47:02 -04:00
/**
2022-03-18 12:31:49 -04:00
* Claim smart object from object and slot handles .
* @ param Handle Handle to the smart object .
* @ param Filter Optional filter to apply on object and slots .
* @ return A handle binding the claimed smart object , its slot and a user id .
2022-03-16 03:47:02 -04:00
*/
2023-06-08 10:34:40 -04:00
UE_DEPRECATED ( 5.3 , " Please use both FindSlots and MarkSlotAsClaimed using only the slot handle. This will allow proper support of selection conditions. " )
2023-02-02 18:43:13 -05:00
[ [ nodiscard ] ] FSmartObjectClaimHandle Claim ( const FSmartObjectHandle Handle , const FSmartObjectRequestFilter & Filter ) ;
2023-06-08 10:34:40 -04:00
/**
* Marks a smart object slot as claimed .
* @ param SlotHandle Handle to a smart object slot .
2023-11-30 02:26:33 -05:00
* @ param ClaimPriority Claim priority , a slot claimed at lower priority can be claimed by higher priority ( unless already in use ) .
2023-06-08 10:34:40 -04:00
* @ param UserData Instanced struct that represents the interacting agent .
* @ return A handle binding the claimed smart object , its slot and a user id .
*/
2023-11-30 02:26:33 -05:00
[ [ nodiscard ] ] FSmartObjectClaimHandle MarkSlotAsClaimed ( const FSmartObjectSlotHandle SlotHandle , ESmartObjectClaimPriority ClaimPriority , const FConstStructView UserData = { } ) ;
UE_DEPRECATED ( 5.4 , " Please use version of MarkSlotAsClaimed() with claim priority. " )
2023-06-08 10:34:40 -04:00
[ [ nodiscard ] ] FSmartObjectClaimHandle MarkSlotAsClaimed ( const FSmartObjectSlotHandle SlotHandle , const FConstStructView UserData = { } ) ;
2022-03-18 12:31:49 -04:00
/**
* Indicates if the object referred to by the given handle is still accessible in the simulation .
* This should only be required when a handle is stored and used later .
* @ param Handle Handle to the smart object .
* @ return True if the handle is valid and its associated object is accessible ; false otherwise .
*/
bool IsSmartObjectValid ( const FSmartObjectHandle Handle ) const ;
2021-09-28 13:33:17 -04:00
/**
2022-03-16 03:47:02 -04:00
* Indicates if the object / slot referred to by the given handle are still accessible in the simulation .
* This should only be required when a handle is stored and later needed to access slot or object information ( e . g . SlotView )
* Otherwise a valid ClaimHandle can be use directly after calling ' Claim ' .
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
* @ return True if the claim handle is valid and its associated object is accessible ; false otherwise .
2022-03-16 03:47:02 -04:00
*/
2022-03-18 12:31:49 -04:00
bool IsClaimedSmartObjectValid ( const FSmartObjectClaimHandle & ClaimHandle ) const ;
2022-03-16 03:47:02 -04:00
/**
* Indicates if the slot referred to by the given handle is still accessible in the simulation .
* This should only be required when a handle is stored and later needed to access slot information ( e . g . SlotView )
* Otherwise a valid SlotHandle can be use directly after calling any of the ' Find ' or ' Claim ' methods .
2022-03-18 12:31:49 -04:00
* @ param SlotHandle Handle to a smart object slot .
* @ return True if the handle is valid and its associated slot is accessible ; false otherwise .
2022-03-16 03:47:02 -04:00
*/
2023-07-18 08:42:51 -04:00
bool IsSmartObjectSlotValid ( const FSmartObjectSlotHandle SlotHandle ) const
{
if ( ! SlotHandle . IsValid ( ) )
{
return false ;
}
const FSmartObjectRuntime * SmartObjectRuntime = RuntimeSmartObjects . Find ( SlotHandle . SmartObjectHandle ) ;
return SmartObjectRuntime ! = nullptr & & SmartObjectRuntime - > Slots . IsValidIndex ( SlotHandle . GetSlotIndex ( ) ) ;
}
2022-03-16 03:47:02 -04:00
/**
* Start using a claimed smart object slot .
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
2022-03-16 03:47:02 -04:00
* @ param DefinitionClass The type of behavior definition the user wants to use .
* @ return The base class pointer of the requested behavior definition class associated to the slot
2021-09-28 13:33:17 -04:00
*/
2023-06-08 10:34:40 -04:00
UE_DEPRECATED ( 5.3 , " Please use MarkSmartObjectSlotAsOccupied instead " )
UFUNCTION ( BlueprintCallable , Category = " SmartObject " , meta = ( DeprecatedFunction , DeprecationMessage = " Use MarkSmartObjectSlotAsOccupied instead. " ) )
const USmartObjectBehaviorDefinition * Use ( const FSmartObjectClaimHandle & ClaimHandle , TSubclassOf < USmartObjectBehaviorDefinition > DefinitionClass )
{
return MarkSlotAsOccupied ( ClaimHandle , DefinitionClass ) ;
}
2021-09-28 13:33:17 -04:00
2022-09-01 09:03:19 -04:00
/**
2023-06-08 10:34:40 -04:00
* Marks a previously claimed smart object slot as occupied .
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
* @ param DefinitionClass The type of behavior definition the user wants to use .
* @ return The base class pointer of the requested behavior definition class associated to the slot
2022-09-01 09:03:19 -04:00
*/
2023-06-08 10:34:40 -04:00
const USmartObjectBehaviorDefinition * MarkSlotAsOccupied ( const FSmartObjectClaimHandle & ClaimHandle , TSubclassOf < USmartObjectBehaviorDefinition > DefinitionClass ) ;
2022-09-01 09:03:19 -04:00
2021-09-28 13:33:17 -04:00
/**
2022-03-16 03:47:02 -04:00
* Start using a claimed smart object slot .
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
2022-03-16 03:47:02 -04:00
* @ return The requested behavior definition class pointer associated to the slot
2021-09-28 13:33:17 -04:00
*/
2021-11-26 12:55:06 -05:00
template < typename DefinitionType >
2023-06-08 10:34:40 -04:00
UE_DEPRECATED ( 5.3 , " Please use MarkSlotAsOccupied instead " )
2021-11-26 12:55:06 -05:00
const DefinitionType * Use ( const FSmartObjectClaimHandle & ClaimHandle )
2021-09-28 13:33:17 -04:00
{
2021-11-26 12:55:06 -05:00
static_assert ( TIsDerivedFrom < DefinitionType , USmartObjectBehaviorDefinition > : : IsDerived , " DefinitionType must derive from USmartObjectBehaviorDefinition " ) ;
2023-06-08 10:34:40 -04:00
return Cast < const DefinitionType > ( MarkSlotAsOccupied ( ClaimHandle , DefinitionType : : StaticClass ( ) ) ) ;
}
/**
* Marks a previously claimed smart object slot as occupied .
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
* @ return The requested behavior definition class pointer associated to the slot
*/
template < typename DefinitionType >
const DefinitionType * MarkSlotAsOccupied ( const FSmartObjectClaimHandle & ClaimHandle )
{
static_assert ( TIsDerivedFrom < DefinitionType , USmartObjectBehaviorDefinition > : : IsDerived , " DefinitionType must derive from USmartObjectBehaviorDefinition " ) ;
return Cast < const DefinitionType > ( MarkSlotAsOccupied ( ClaimHandle , DefinitionType : : StaticClass ( ) ) ) ;
2021-09-28 13:33:17 -04:00
}
/**
2022-03-16 03:47:02 -04:00
* Release claim on a smart object .
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
2022-03-16 03:47:02 -04:00
* @ return Whether the claim was successfully released or not
2021-09-28 13:33:17 -04:00
*/
2023-06-08 10:34:40 -04:00
UFUNCTION ( BlueprintCallable , Category = " SmartObject " , meta = ( DeprecatedFunction , DeprecationMessage = " Use MarkSmartObjectSlotAsFree instead. " ) )
bool Release ( const FSmartObjectClaimHandle & ClaimHandle )
{
return MarkSlotAsFree ( ClaimHandle ) ;
}
/**
* Marks a claimed or occupied smart object as free .
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
* @ return Whether the claim was successfully released or not
*/
bool MarkSlotAsFree ( const FSmartObjectClaimHandle & ClaimHandle ) ;
2021-09-28 13:33:17 -04:00
2022-01-26 17:33:02 -05:00
/**
2022-03-16 03:47:02 -04:00
* Return the behavior definition of a given type from a claimed object .
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
2022-03-16 03:47:02 -04:00
* @ param DefinitionClass The type of behavior definition .
* @ return The base class pointer of the requested behavior definition class associated to the slotClaim handle
2022-01-26 17:33:02 -05:00
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
2023-02-02 18:43:13 -05:00
const USmartObjectBehaviorDefinition * GetBehaviorDefinition (
const FSmartObjectClaimHandle & ClaimHandle ,
2023-04-21 16:47:40 -04:00
TSubclassOf < USmartObjectBehaviorDefinition > DefinitionClass
2023-02-02 18:43:13 -05:00
) ;
2022-01-26 17:33:02 -05:00
/**
2022-03-16 03:47:02 -04:00
* Return the behavior definition of a given type from a claimed object .
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
2022-03-16 03:47:02 -04:00
* @ return The requested behavior definition class pointer associated to the Claim handle
2022-01-26 17:33:02 -05:00
*/
template < typename DefinitionType >
const DefinitionType * GetBehaviorDefinition ( const FSmartObjectClaimHandle & ClaimHandle )
{
static_assert ( TIsDerivedFrom < DefinitionType , USmartObjectBehaviorDefinition > : : IsDerived , " DefinitionType must derive from USmartObjectBehaviorDefinition " ) ;
return Cast < const DefinitionType > ( GetBehaviorDefinition ( ClaimHandle , DefinitionType : : StaticClass ( ) ) ) ;
}
2022-09-16 12:46:45 -04:00
/**
* Return the behavior definition of a given type from a request result .
* @ param RequestResult A request result returned by any of the Find methods .
* @ param DefinitionClass The type of behavior definition .
* @ return The base class pointer of the requested behavior definition class associated to the request result
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
2023-02-02 18:43:13 -05:00
const USmartObjectBehaviorDefinition * GetBehaviorDefinitionByRequestResult (
const FSmartObjectRequestResult & RequestResult ,
2023-04-21 16:47:40 -04:00
TSubclassOf < USmartObjectBehaviorDefinition > DefinitionClass
2023-02-02 18:43:13 -05:00
) ;
2022-09-16 12:46:45 -04:00
/**
* Return the behavior definition of a given type from a claimed object .
* @ param RequestResult A request result returned by any of the Find methods .
* @ return The requested behavior definition class pointer associated to the request result
*/
template < typename DefinitionType >
const DefinitionType * GetBehaviorDefinition ( const FSmartObjectRequestResult & RequestResult )
{
static_assert ( TIsDerivedFrom < DefinitionType , USmartObjectBehaviorDefinition > : : IsDerived , " DefinitionType must derive from USmartObjectBehaviorDefinition " ) ;
2022-09-20 09:09:25 -04:00
return Cast < const DefinitionType > ( GetBehaviorDefinitionByRequestResult ( RequestResult , DefinitionType : : StaticClass ( ) ) ) ;
2022-09-16 12:46:45 -04:00
}
2023-09-05 11:29:58 -04:00
/**
* Returns the state of the given Smart Object Slot handle .
*/
UFUNCTION ( BlueprintCallable , BlueprintPure , Category = " SmartObject " )
2022-03-17 19:07:54 -04:00
ESmartObjectSlotState GetSlotState ( const FSmartObjectSlotHandle SlotHandle ) const ;
2022-01-19 14:16:16 -05:00
2023-07-18 08:42:51 -04:00
UE_DEPRECATED ( 5.3 , " Data is now added synchronously, use AddSlotData instead. " )
void AddSlotDataDeferred ( const FSmartObjectClaimHandle & ClaimHandle , FConstStructView InData ) { AddSlotData ( ClaimHandle , InData ) ; }
2022-01-19 14:16:16 -05:00
/**
2023-07-18 08:42:51 -04:00
* Adds state data to a slot instance . Data must be a struct that inherits
2022-01-19 14:16:16 -05:00
* from FSmartObjectSlotStateData and passed as a struct view ( e . g . FConstStructView : : Make ( FSomeStruct ) )
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
* @ param InData A view on the struct to add .
2022-01-19 14:16:16 -05:00
*/
2023-07-18 08:42:51 -04:00
void AddSlotData ( const FSmartObjectClaimHandle & ClaimHandle , FConstStructView InData ) ;
2022-01-19 14:16:16 -05:00
2022-03-16 03:47:02 -04:00
/**
2022-03-18 12:31:49 -04:00
* Creates and returns a view to the data associated to a slot handle .
* @ return A view on the slot associated to SlotHandle . Caller should use IsValid ( ) on the view
* before using it since the provided handle might no longer refer to a slot registered in the simulation .
2022-03-16 03:47:02 -04:00
*/
2022-03-17 19:07:54 -04:00
FSmartObjectSlotView GetSlotView ( const FSmartObjectSlotHandle SlotHandle ) const ;
2022-01-19 14:16:16 -05:00
2021-09-28 13:33:17 -04:00
/**
* Returns the position ( in world space ) of the slot associated to the given claim handle .
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
2021-09-28 13:33:17 -04:00
* @ return Position ( in world space ) of the slot associated to ClaimHandle .
*/
2022-03-18 12:31:49 -04:00
TOptional < FVector > GetSlotLocation ( const FSmartObjectClaimHandle & ClaimHandle ) const { return GetSlotLocation ( ClaimHandle . SlotHandle ) ; }
2021-11-22 16:32:17 -05:00
/**
* Returns the position ( in world space ) of the slot associated to the given claim handle .
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
2021-11-22 16:32:17 -05:00
* @ param OutSlotLocation Position ( in world space ) of the slot associated to ClaimHandle .
* @ return Whether the location was found and assigned to ' OutSlotLocation '
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
bool GetSlotLocation ( const FSmartObjectClaimHandle & ClaimHandle , FVector & OutSlotLocation ) const ;
2021-09-28 13:33:17 -04:00
/**
* Returns the position ( in world space ) of the slot associated to the given request result .
2022-03-18 12:31:49 -04:00
* @ param Result A request result returned by any of the Find methods .
2022-02-17 03:40:43 -05:00
* @ return Position ( in world space ) of the slot associated to Result .
2021-09-28 13:33:17 -04:00
*/
2022-03-18 12:31:49 -04:00
TOptional < FVector > GetSlotLocation ( const FSmartObjectRequestResult & Result ) const { return GetSlotLocation ( Result . SlotHandle ) ; }
2021-09-28 13:33:17 -04:00
/**
2022-01-19 14:16:16 -05:00
* Returns the position ( in world space ) of the slot represented by the provided slot handle .
* @ param SlotHandle Handle to a smart object slot .
2022-02-17 03:40:43 -05:00
* @ return Position ( in world space ) of the slot associated to SlotHandle .
2021-09-28 13:33:17 -04:00
*/
2022-03-17 19:07:54 -04:00
TOptional < FVector > GetSlotLocation ( const FSmartObjectSlotHandle SlotHandle ) const ;
2021-09-28 13:33:17 -04:00
/**
* Returns the transform ( in world space ) of the slot associated to the given claim handle .
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
2021-09-28 13:33:17 -04:00
* @ return Transform ( in world space ) of the slot associated to ClaimHandle .
*/
2022-03-18 12:31:49 -04:00
TOptional < FTransform > GetSlotTransform ( const FSmartObjectClaimHandle & ClaimHandle ) const { return GetSlotTransform ( ClaimHandle . SlotHandle ) ; }
2021-09-28 13:33:17 -04:00
2021-11-22 16:32:17 -05:00
/**
* Returns the transform ( in world space ) of the slot associated to the given claim handle .
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
2021-11-22 16:32:17 -05:00
* @ param OutSlotTransform Transform ( in world space ) of the slot associated to ClaimHandle .
* @ return Whether the transform was found and assigned to ' OutSlotTransform '
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
bool GetSlotTransform ( const FSmartObjectClaimHandle & ClaimHandle , FTransform & OutSlotTransform ) const ;
2022-03-18 12:31:49 -04:00
2021-09-28 13:33:17 -04:00
/**
* Returns the transform ( in world space ) of the slot associated to the given request result .
2022-03-18 12:31:49 -04:00
* @ param Result A request result returned by any of the Find methods .
2022-02-17 03:40:43 -05:00
* @ return Transform ( in world space ) of the slot associated to Result .
2021-09-28 13:33:17 -04:00
*/
2022-03-18 12:31:49 -04:00
TOptional < FTransform > GetSlotTransform ( const FSmartObjectRequestResult & Result ) const { return GetSlotTransform ( Result . SlotHandle ) ; }
2021-09-28 13:33:17 -04:00
2022-09-15 15:11:53 -04:00
/**
* Returns the transform ( in world space ) of the slot associated to the given RequestResult .
* @ param RequestResult Result returned by any of the Find Smart Object ( s ) methods .
* @ param OutSlotTransform Transform ( in world space ) of the slot associated to the RequestResult .
* @ return Whether the transform was found and assigned to ' OutSlotTransform '
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
bool GetSlotTransformFromRequestResult ( const FSmartObjectRequestResult & RequestResult , FTransform & OutSlotTransform ) const ;
2021-09-28 13:33:17 -04:00
/**
2022-01-19 14:16:16 -05:00
* Returns the transform ( in world space ) of the slot represented by the provided slot handle .
* @ param SlotHandle Handle to a smart object slot .
2022-02-17 03:40:43 -05:00
* @ return Transform ( in world space ) of the slot associated to SlotHandle .
2021-09-28 13:33:17 -04:00
*/
2022-03-17 19:07:54 -04:00
TOptional < FTransform > GetSlotTransform ( const FSmartObjectSlotHandle SlotHandle ) const ;
2022-02-17 03:40:43 -05:00
2022-09-01 09:03:19 -04:00
/**
* Similarly to GetSlotTransform fetches the transform ( in world space ) of the indicated slot , but assumes the slot
* handle is valid and that the EntityManager is known . The burden of ensuring that ' s the case is on the caller .
* @ param SlotHandle Handle to a smart object slot .
* @ return Transform ( in world space ) of the slot associated to SlotHandle .
*/
2023-07-18 08:42:51 -04:00
FTransform GetSlotTransformChecked ( const FSmartObjectSlotHandle SlotHandle ) const ;
2022-09-01 09:03:19 -04:00
2021-09-28 13:33:17 -04:00
/**
2022-03-18 12:31:49 -04:00
* Returns the list of tags associated to the smart object instance represented by the provided handle .
* @ param Handle Handle to the smart object .
* @ return Container of tags associated to the smart object instance .
2022-03-16 03:47:02 -04:00
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
const FGameplayTagContainer & GetInstanceTags ( const FSmartObjectHandle Handle ) const ;
/**
2022-03-18 12:31:49 -04:00
* Adds a single tag to the smart object instance represented by the provided handle .
* @ param Handle Handle to the smart object .
* @ param Tag Tag to add to the smart object instance .
2022-03-16 03:47:02 -04:00
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
void AddTagToInstance ( const FSmartObjectHandle Handle , const FGameplayTag & Tag ) ;
/**
* Removes a single tag from the smartobject instance represented by the provided handle .
2022-03-18 12:31:49 -04:00
* @ param Handle Handle to the smart object .
2022-03-16 03:47:02 -04:00
* @ param Tag Tag to remove from the SmartObject instance .
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
void RemoveTagFromInstance ( const FSmartObjectHandle Handle , const FGameplayTag & Tag ) ;
2023-01-18 10:52:51 -05:00
/**
* Returns pointer to the smart object instance event delegate .
* @ param SmartObjectHandle Handle to the smart object .
* @ return Pointer to object ' s delegate , or nullptr if instance doesn ' t exists .
*/
FOnSmartObjectEvent * GetEventDelegate ( const FSmartObjectHandle SmartObjectHandle ) ;
2022-11-01 15:11:25 -04:00
/**
* Returns the list of tags associated to the smart object slot represented by the provided handle .
* @ param SlotHandle Handle to the smart object slot .
* @ return Container of tags associated to the smart object instance , or empty container if slot was not valid .
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
const FGameplayTagContainer & GetSlotTags ( const FSmartObjectSlotHandle SlotHandle ) const ;
/**
* Adds a single tag to the smart object slot represented by the provided handle .
* @ param SlotHandle Handle to the smart object slot .
* @ param Tag Tag to add to the smart object slot .
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
void AddTagToSlot ( const FSmartObjectSlotHandle SlotHandle , const FGameplayTag & Tag ) ;
/**
* Removes a single tag from the smart object slot represented by the provided handle .
* @ param SlotHandle Handle to the smart object slot .
* @ param Tag Tag to remove from the smart object slot .
* @ return True if the tag was removed .
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
bool RemoveTagFromSlot ( const FSmartObjectSlotHandle SlotHandle , const FGameplayTag & Tag ) ;
/**
* Enables or disables the smart object slot represented by the provided handle .
* @ param SlotHandle Handle to the smart object slot .
* @ param bEnabled If true enables the slot , if false , disables the slot .
2022-11-04 09:18:52 -04:00
* @ return Previous enabled state .
2022-11-01 15:11:25 -04:00
*/
UFUNCTION ( BlueprintCallable , Category = " SmartObject " )
2022-11-04 09:18:52 -04:00
bool SetSlotEnabled ( const FSmartObjectSlotHandle SlotHandle , const bool bEnabled ) ;
2022-11-01 15:11:25 -04:00
/**
* Sends event to a Smart Object slot .
* @ param SlotHandle Handle to the smart object slot .
* @ param EventTag Gameplay Tag describing the event type .
* @ param Payload Struct payload for the event .
* @ return True if the event was successfully sent .
*/
bool SendSlotEvent ( const FSmartObjectSlotHandle SlotHandle , const FGameplayTag EventTag , const FConstStructView Payload = FConstStructView ( ) ) ;
/**
2023-02-02 18:43:13 -05:00
* Returns pointer to the smart object changed delegate associated to the provided handle .
* The delegate is shared for all slots so listeners must filter using ' Event . SlotHandle ' .
2022-11-01 15:11:25 -04:00
* @ param SlotHandle Handle to the smart object slot .
* @ return Pointer to slot ' s delegate , or nullptr if slot does not exists .
*/
FOnSmartObjectEvent * GetSlotEventDelegate ( const FSmartObjectSlotHandle SlotHandle ) ;
2022-03-16 03:47:02 -04:00
/**
* Register a callback to be notified if the claimed slot is no longer available and user need to perform cleanup .
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
2022-03-16 03:47:02 -04:00
* @ param Callback Delegate that will be called to notify that a slot gets invalidated and can no longer be used .
2021-09-28 13:33:17 -04:00
*/
void RegisterSlotInvalidationCallback ( const FSmartObjectClaimHandle & ClaimHandle , const FOnSlotInvalidated & Callback ) ;
/**
2022-03-16 03:47:02 -04:00
* Unregisters a callback to be notified if the claimed slot is no longer available and user need to perform cleanup .
2022-03-18 12:31:49 -04:00
* @ param ClaimHandle Handle to a claimed slot returned by any of the Claim methods .
2021-09-28 13:33:17 -04:00
*/
void UnregisterSlotInvalidationCallback ( const FSmartObjectClaimHandle & ClaimHandle ) ;
2022-02-21 01:10:34 -05:00
# if UE_ENABLE_DEBUG_DRAWING
void DebugDraw ( FDebugRenderSceneProxy * DebugProxy ) const ;
void DebugDrawCanvas ( UCanvas * Canvas , APlayerController * PlayerController ) const { }
# endif
2022-11-24 14:53:52 -05:00
# if WITH_EDITORONLY_DATA
/**
* Special - purpose function used to set up an instance of ASmartObjectPersistentCollection with data from a given
* instance of ADEPRECATED_SmartObjectCollection
*/
static void CreatePersistentCollectionFromDeprecatedData ( UWorld & World , const ADEPRECATED_SmartObjectCollection & DeprecatedCollection ) ;
TConstArrayView < TWeakObjectPtr < ASmartObjectPersistentCollection > > GetRegisteredCollections ( ) const { return RegisteredCollections ; }
TArrayView < TWeakObjectPtr < ASmartObjectPersistentCollection > > GetMutableRegisteredCollections ( ) { return RegisteredCollections ; }
# endif // WITH_EDITORONLY_DATA
2021-11-03 15:46:53 -04:00
# if WITH_EDITOR
2022-02-25 14:18:42 -05:00
mutable FOnMainCollectionEvent OnMainCollectionChanged ;
mutable FOnMainCollectionEvent OnMainCollectionDirtied ;
2021-11-03 15:46:53 -04:00
# endif
2021-09-28 13:33:17 -04:00
protected :
2022-11-24 14:53:52 -05:00
friend UWorldPartitionSmartObjectCollectionBuilder ;
2021-11-02 11:09:09 -04:00
2022-03-30 15:13:42 -04:00
bool RegisterSmartObjectInternal ( USmartObjectComponent & SmartObjectComponent ) ;
2022-12-07 13:05:23 -05:00
bool UnregisterSmartObjectInternal ( USmartObjectComponent & SmartObjectComponent , const bool bDestroyRuntimeState ) ;
UE_DEPRECATED ( 5.2 , " This flavor of UnregisterSmartObjectInternal is deprecated. Please use UnregisterSmartObjectInternal(USmartObjectComponent&, const bool) instead. " )
PRAGMA_DISABLE_DEPRECATION_WARNINGS
2022-03-30 15:13:42 -04:00
bool UnregisterSmartObjectInternal ( USmartObjectComponent & SmartObjectComponent , const ESmartObjectUnregistrationMode UnregistrationMode ) ;
2022-12-07 13:05:23 -05:00
PRAGMA_ENABLE_DEPRECATION_WARNINGS
2022-03-30 15:13:42 -04:00
2021-11-02 11:09:09 -04:00
/**
2022-12-07 13:05:23 -05:00
* Callback overridden to gather loaded collections , spawn missing one and set the main collection .
2021-11-02 11:09:09 -04:00
* @ note we use this method instead of ` Initialize ` or ` PostInitialize ` so active level is set and actors registered .
*/
virtual void OnWorldComponentsUpdated ( UWorld & World ) override ;
/**
* BeginPlay will push all objects stored in the collection to the runtime simulation
* and initialize octree using collection bounds .
*/
virtual void OnWorldBeginPlay ( UWorld & World ) override ;
2021-09-28 13:33:17 -04:00
2022-08-29 11:12:18 -04:00
// USubsystem BEGIN
virtual void Deinitialize ( ) override ;
2022-11-23 08:17:20 -05:00
virtual bool ShouldCreateSubsystem ( UObject * Outer ) const override ;
2022-08-29 11:12:18 -04:00
// USubsystem END
2022-02-17 03:40:43 -05:00
/** Creates all runtime data using main collection */
void InitializeRuntime ( ) ;
2023-07-18 08:42:51 -04:00
UE_DEPRECATED ( 5.3 , " Use InitializeRuntime() without Mass entity manager. " )
void InitializeRuntime ( const TSharedPtr < FMassEntityManager > & InEntityManager )
{
}
2022-02-17 03:40:43 -05:00
/** Removes all runtime data */
2022-11-07 09:57:31 -05:00
virtual void CleanupRuntime ( ) ;
2022-02-17 03:40:43 -05:00
2022-03-16 03:47:02 -04:00
/** Returns the runtime instance associated to the provided handle */
2022-03-17 19:07:54 -04:00
FSmartObjectRuntime * GetRuntimeInstance ( const FSmartObjectHandle SmartObjectHandle ) { return RuntimeSmartObjects . Find ( SmartObjectHandle ) ; }
2022-03-16 03:47:02 -04:00
2023-02-28 10:24:32 -05:00
/** Returns the const runtime instance associated to the provided handle */
const FSmartObjectRuntime * GetRuntimeInstance ( const FSmartObjectHandle SmartObjectHandle ) const { return RuntimeSmartObjects . Find ( SmartObjectHandle ) ; }
2022-03-18 12:31:49 -04:00
/**
* Indicates if the handle is set and the slot referred to is still accessible in the simulation .
* Log is produced for any failing condition using provided LogContext .
* @ param SlotHandle Handle to a smart object slot .
* @ param LogContext String describing the context in which the method is called ( e . g . caller function name )
* @ return True if the handle is valid and its associated slot is accessible ; false otherwise .
*/
bool IsSlotValidVerbose ( const FSmartObjectSlotHandle SlotHandle , const TCHAR * LogContext ) const ;
2023-07-18 08:42:51 -04:00
/**
* Returns the const runtime instance associated to the provided handle .
* Method produces log messages with provided context if provided handle is not set or associated instance can ' t be found .
*/
bool GetValidatedRuntimeAndSlot ( const FSmartObjectSlotHandle SlotHandle , const FSmartObjectRuntime * & OutSmartObjectRuntime , const FSmartObjectRuntimeSlot * & OutSlot , const TCHAR * Context ) const ;
/**
* Returns the mutable runtime instance associated to the provided handle
* Method produces log messages with provided context if provided handle is not set or associated instance can ' t be found .
*/
bool GetValidatedMutableRuntimeAndSlot ( const FSmartObjectSlotHandle SlotHandle , FSmartObjectRuntime * & OutSmartObjectRuntime , FSmartObjectRuntimeSlot * & OutSlot , const TCHAR * Context ) ;
UE_DEPRECATED ( 5.3 , " Use GetValidatedRuntimeAndSlot() instead. " )
const FSmartObjectRuntimeSlot * GetSlotVerbose ( const FSmartObjectSlotHandle SlotHandle , const TCHAR * LogContext ) const
{
return nullptr ;
}
UE_DEPRECATED ( 5.3 , " Use GetValidatedMutableRuntimeAndSlot() instead. " )
FSmartObjectRuntimeSlot * GetMutableSlotVerbose ( const FSmartObjectSlotHandle SlotHandle , const TCHAR * LogContext )
{
return nullptr ;
}
UE_DEPRECATED ( 5.3 , " Use GetValidatedMutableRuntimeAndSlot() instead. " )
FSmartObjectRuntimeSlot * GetMutableSlot ( const FSmartObjectClaimHandle & ClaimHandle )
{
return nullptr ;
}
2022-03-18 12:31:49 -04:00
2022-03-16 03:47:02 -04:00
/**
* Returns the const runtime instance associated to the provided handle .
2022-03-18 12:31:49 -04:00
* Method produces log messages with provided context if provided handle is not set or associated instance can ' t be found .
2022-03-16 03:47:02 -04:00
*/
2022-03-17 19:07:54 -04:00
const FSmartObjectRuntime * GetValidatedRuntime ( const FSmartObjectHandle Handle , const TCHAR * Context ) const ;
2022-03-16 03:47:02 -04:00
/**
* Returns the mutable runtime instance associated to the provided handle
2022-03-18 12:31:49 -04:00
* Method produces log messages with provided context if provided handle is not set or associated instance can ' t be found .
2022-03-16 03:47:02 -04:00
*/
2022-11-01 15:11:25 -04:00
FSmartObjectRuntime * GetValidatedMutableRuntime ( const FSmartObjectHandle Handle , const TCHAR * Context ) const ;
2022-03-16 03:47:02 -04:00
2023-02-02 18:43:13 -05:00
static void AddTagToInstance ( FSmartObjectRuntime & SmartObjectRuntime , const FGameplayTag & Tag ) ;
static void RemoveTagFromInstance ( FSmartObjectRuntime & SmartObjectRuntime , const FGameplayTag & Tag ) ;
static void OnSlotChanged (
const FSmartObjectRuntime & SmartObjectRuntime ,
const FSmartObjectRuntimeSlot & Slot ,
const FSmartObjectSlotHandle SlotHandle ,
const ESmartObjectChangeReason Reason ,
const FConstStructView Payload = { } ,
const FGameplayTag ChangedTag = FGameplayTag ( )
) ;
2022-03-16 03:47:02 -04:00
2022-03-02 13:25:37 -05:00
/** Goes through all defined slots of smart object represented by SmartObjectRuntime and finds the ones matching the filter. */
2023-02-02 18:43:13 -05:00
void FindSlots (
2023-07-18 08:42:51 -04:00
const FSmartObjectHandle Handle ,
2023-02-02 18:43:13 -05:00
const FSmartObjectRuntime & SmartObjectRuntime ,
const FSmartObjectRequestFilter & Filter ,
TArray < FSmartObjectSlotHandle > & OutResults ,
const FConstStructView UserData ) const ;
2022-03-02 13:25:37 -05:00
2023-07-18 08:42:51 -04:00
UE_DEPRECATED ( 5.3 , " FindSlots() was changed to require object handle as parameter too. " )
void FindSlots (
const FSmartObjectRuntime & SmartObjectRuntime ,
const FSmartObjectRequestFilter & Filter ,
TArray < FSmartObjectSlotHandle > & OutResults ,
const FConstStructView UserData ) const
{
}
2022-03-02 13:25:37 -05:00
/** Applies filter on provided definition and fills OutValidIndices with indices of all valid slots. */
static void FindMatchingSlotDefinitionIndices ( const USmartObjectDefinition & Definition , const FSmartObjectRequestFilter & Filter , TArray < int32 > & OutValidIndices ) ;
2021-09-28 13:33:17 -04:00
2023-02-02 18:43:13 -05:00
static const USmartObjectBehaviorDefinition * GetBehaviorDefinition (
const FSmartObjectRuntime & SmartObjectRuntime ,
const FSmartObjectSlotHandle SlotHandle ,
2023-04-21 16:47:40 -04:00
TSubclassOf < USmartObjectBehaviorDefinition > DefinitionClass
2023-02-02 18:43:13 -05:00
) ;
2022-01-26 17:33:02 -05:00
2023-06-08 10:34:40 -04:00
const USmartObjectBehaviorDefinition * MarkSlotAsOccupied (
2023-07-18 08:42:51 -04:00
FSmartObjectRuntime & SmartObjectRuntime ,
2023-02-02 18:43:13 -05:00
const FSmartObjectClaimHandle & ClaimHandle ,
2023-04-21 16:47:40 -04:00
TSubclassOf < USmartObjectBehaviorDefinition > DefinitionClass
2023-02-02 18:43:13 -05:00
) ;
2021-09-28 13:33:17 -04:00
2023-07-18 08:42:51 -04:00
UE_DEPRECATED ( 5.3 , " MarkSlotAsOccupied() was changed to require SmartObjectRuntime to be passed as mutable. " )
const USmartObjectBehaviorDefinition * MarkSlotAsOccupied (
const FSmartObjectRuntime & SmartObjectRuntime ,
const FSmartObjectClaimHandle & ClaimHandle ,
TSubclassOf < USmartObjectBehaviorDefinition > DefinitionClass
)
{
return nullptr ;
}
2021-09-28 13:33:17 -04:00
2023-07-18 08:42:51 -04:00
void AbortAll ( const FSmartObjectHandle Handle , FSmartObjectRuntime & SmartObjectRuntime ) const ;
2021-09-28 13:33:17 -04:00
2023-07-18 08:42:51 -04:00
UE_DEPRECATED ( 5.3 , " AbortAll() was changed to require object handle as parameter too. " )
void AbortAll ( const FSmartObjectRuntime & SmartObjectRuntime )
{
}
2021-09-28 13:33:17 -04:00
/** Make sure that all SmartObjectCollection actors from our associated world are registered. */
void RegisterCollectionInstances ( ) ;
2022-11-24 14:53:52 -05:00
void AddContainerToSimulation ( const FSmartObjectContainer & InSmartObjectContainer ) ;
2022-03-16 03:47:02 -04:00
/**
* Registers a collection entry to the simulation and creates its associated runtime instance .
*/
2023-02-02 18:43:13 -05:00
FSmartObjectRuntime * AddCollectionEntryToSimulation (
const FSmartObjectCollectionEntry & Entry ,
const USmartObjectDefinition & Definition ,
2023-07-18 08:42:51 -04:00
USmartObjectComponent * OwnerComponent
2023-02-02 18:43:13 -05:00
) ;
2022-03-16 03:47:02 -04:00
2023-07-18 08:42:51 -04:00
UE_DEPRECATED ( 5.3 , " bCommitChanges is not used anymore, use the version without. " )
FSmartObjectRuntime * AddCollectionEntryToSimulation (
const FSmartObjectCollectionEntry & Entry ,
const USmartObjectDefinition & Definition ,
USmartObjectComponent * OwnerComponent ,
const bool bCommitChanges )
{
return nullptr ;
}
2022-03-16 03:47:02 -04:00
/**
* Registers a collection entry to the simulation and creates its associated runtime instance .
* @ param SmartObjectComponent The component to add to the simulation and for which a runtime entry might be created or an existing one found
* @ param CollectionEntry The associated collection entry that got created to add the component to the simulation .
2023-02-02 18:43:13 -05:00
* @ param bCommitChanges Indicates if deferred commands must be flushed . Set to ' true ' by default but could be set to ' false ' when adding batch of components .
2022-03-16 03:47:02 -04:00
*/
2023-02-02 18:43:13 -05:00
FSmartObjectRuntime * AddComponentToSimulation (
USmartObjectComponent & SmartObjectComponent ,
2023-07-18 08:42:51 -04:00
const FSmartObjectCollectionEntry & CollectionEntry
2023-02-02 18:43:13 -05:00
) ;
2022-03-16 03:47:02 -04:00
2023-07-18 08:42:51 -04:00
UE_DEPRECATED ( 5.3 , " bCommitChanges is not used anymore, use the version without. " )
FSmartObjectRuntime * AddComponentToSimulation (
USmartObjectComponent & SmartObjectComponent ,
const FSmartObjectCollectionEntry & CollectionEntry ,
const bool bCommitChanges
)
{
return nullptr ;
}
2023-02-02 18:43:13 -05:00
/** Notifies SmartObjectComponent that it has been bound to a runtime instance, and sets SmartObjectComponent-related properties of SmartObjectRuntime */
void BindComponentToSimulationInternal ( USmartObjectComponent & SmartObjectComponent , FSmartObjectRuntime & SmartObjectRuntime ) ;
2022-03-16 03:47:02 -04:00
/**
* Unbinds a smartobject component from an existing instance in the simulation .
* @ param SmartObjectComponent The component to remove from the simulation
*/
void UnbindComponentFromSimulation ( USmartObjectComponent & SmartObjectComponent ) ;
2022-11-24 14:53:52 -05:00
/**
* Unbinds a smartobject component from the given FSmartObjectRuntime instance . Note that unlike UnbindComponentFromSimulation
* this function blindly assumes that SmartObjectRuntime does indeed represent SmartObjectComponent
* @ param SmartObjectComponent The component to remove from the simulation
* @ param SmartObjectRuntime runtime data representing the component being removed
*/
2023-02-02 18:43:13 -05:00
static void UnbindComponentFromSimulationInternal ( USmartObjectComponent & SmartObjectComponent , FSmartObjectRuntime & SmartObjectRuntime ) ;
2022-11-24 14:53:52 -05:00
2022-10-26 19:34:40 -04:00
/** @return whether the removal was successful */
2023-05-26 12:48:38 -04:00
bool RemoveRuntimeInstanceFromSimulation ( const FSmartObjectHandle Handle , USmartObjectComponent * SmartObjectComponent ) ;
2022-10-26 19:34:40 -04:00
bool RemoveCollectionEntryFromSimulation ( const FSmartObjectCollectionEntry & Entry ) ;
2023-05-26 12:48:38 -04:00
void RemoveComponentFromSimulation ( USmartObjectComponent & SmartObjectComponent ) ;
2021-09-28 13:33:17 -04:00
2022-10-26 19:34:40 -04:00
/** Destroy SmartObjectRuntime contents as Handle's representation. */
2023-07-18 08:42:51 -04:00
void DestroyRuntimeInstanceInternal ( const FSmartObjectHandle Handle , FSmartObjectRuntime & SmartObjectRuntime ) ;
2022-10-26 19:34:40 -04:00
2023-07-18 08:42:51 -04:00
UE_DEPRECATED ( 5.3 , " EntityManagerRef is not used anymore, use the version without. " )
void DestroyRuntimeInstanceInternal ( const FSmartObjectHandle Handle , FSmartObjectRuntime & SmartObjectRuntime , const FMassEntityManager & EntityManagerRef )
{
}
2023-01-18 10:52:51 -05:00
/**
* Fills the provided context data with the smartobject actor and handle associated to ' SmartObjectRuntime ' and the subsystem .
2023-02-02 18:43:13 -05:00
* @ param ContextData The context data to fill
2023-01-18 10:52:51 -05:00
* @ param SmartObjectRuntime The runtime instance of the SmartObject for which the context must be filled
*/
2023-02-02 18:43:13 -05:00
void SetupConditionContextCommonData ( FWorldConditionContextData & ContextData , const FSmartObjectRuntime & SmartObjectRuntime ) const ;
/**
* Binds properties of the context data to property values of the user data struct when they match type and name .
* @ param ContextData The context data to fill
* @ param UserData Additional data that could be provided to bind values in the conditions evaluation context
*/
void BindPropertiesFromStruct ( FWorldConditionContextData & ContextData , const FConstStructView & UserData ) const ;
2023-01-18 10:52:51 -05:00
/**
* Use the provided context data that is expected to be already filled by calling ' SetupConditionContextCommonData '
* and adds the slot related part . It then evaluates all conditions associated to the specified slot .
* @ param ConditionContextData The context data to fill and use for conditions evaluation
2023-07-18 08:42:51 -04:00
* @ param SmartObjectRuntime Runtime struct associated to the smart object slot
2023-01-18 10:52:51 -05:00
* @ param SlotHandle Handle to the smart object slot
* @ return True if all conditions are met ; false otherwise
* @ see SetupDefaultConditionsContext
*/
2023-07-18 08:42:51 -04:00
[ [ nodiscard ] ] bool EvaluateSlotConditions (
FWorldConditionContextData & ConditionContextData ,
const FSmartObjectRuntime & SmartObjectRuntime ,
const FSmartObjectSlotHandle SlotHandle
) const ;
UE_DEPRECATED ( 5.3 , " Use the version that takes smart object runtime and slot handle. " )
2023-02-02 18:43:13 -05:00
[ [ nodiscard ] ] bool EvaluateSlotConditions (
FWorldConditionContextData & ConditionContextData ,
const FSmartObjectSlotHandle SlotHandle ,
const FSmartObjectRuntimeSlot & Slot
2023-07-18 08:42:51 -04:00
) const
{
return false ;
}
2023-01-18 10:52:51 -05:00
/**
* Use the provided context data that is expected to be already filled by calling ' SetupConditionContextCommonData '
* and evaluates all conditions associated to the specified object .
* @ param ConditionContextData The context data to use for conditions evaluation
* @ param SmartObjectRuntime Runtime data representing the smart object for which the conditions must be evaluated
* @ return True if all conditions are met ; false otherwise
*/
2023-02-02 18:43:13 -05:00
[ [ nodiscard ] ] bool EvaluateObjectConditions ( const FWorldConditionContextData & ConditionContextData , const FSmartObjectRuntime & SmartObjectRuntime ) const ;
2023-01-18 10:52:51 -05:00
2023-02-02 18:43:13 -05:00
/**
* Internal helper for filter methods to build the list of accepted slots
* by reusing context data and schema as much as possible .
*/
[ [ nodiscard ] ] bool EvaluateConditionsForFiltering (
2023-07-18 08:42:51 -04:00
const FSmartObjectRuntime & SmartObjectRuntime ,
2023-02-02 18:43:13 -05:00
const FSmartObjectSlotHandle SlotHandle ,
FWorldConditionContextData & ContextData ,
const FConstStructView UserData ,
TPair < const FSmartObjectRuntime * , bool > & LastEvaluatedRuntime
) const ;
2023-03-17 07:41:24 -04:00
2023-07-18 08:42:51 -04:00
UE_DEPRECATED ( 5.3 , " EvaluateConditionsForFiltering() was changed to rewuire smart object runtime as parameter. " )
[ [ nodiscard ] ] bool EvaluateConditionsForFiltering (
const FSmartObjectSlotHandle SlotHandle ,
FWorldConditionContextData & ContextData ,
const FConstStructView UserData ,
TPair < const FSmartObjectRuntime * , bool > & LastEvaluatedRuntime
) const
{
return false ;
}
2023-03-17 07:41:24 -04:00
/**
* Finds entrance location for a specific slot . Each slot can be annotated with multiple entrance locations , and the request can be configured to also consider the slot location as one entry .
* Additionally the entrance locations can be checked to be on navigable surface ( does not check that the point is reachable , though ) , traced on ground , and without of collisions .
* @ param SlotHandle Handle to the smart object slot .
* @ param SlotEntranceHandle Handle to specific entrance if just one entrance should be checked . ( Optional )
* @ param Request Request describing how to select the entry .
* @ param Result Entry location result ( in world space ) .
* @ return True if valid entry found .
*/
bool FindEntranceLocationInternal (
const FSmartObjectSlotHandle SlotHandle ,
const FSmartObjectSlotEntranceHandle SlotEntranceHandle ,
const FSmartObjectSlotEntranceLocationRequest & Request ,
FSmartObjectSlotEntranceLocationResult & Result
) const ;
2023-08-10 07:02:20 -04:00
/**
* Validates entrance locations for a specific slot . Each slot can be annotated with multiple entrance locations , and the request can be configured to also consider the slot location as one entry .
* Additionally the entrance locations can be checked to be on navigable surface ( does not check that the point is reachable , though ) , traced on ground , and without of collisions .
2023-08-14 03:40:42 -04:00
* @ param World World to use for validation tracing .
2023-08-10 07:02:20 -04:00
* @ param ValidationContext Valid validation context .
* @ param Request Request describing how to validate the entries .
* @ param SlotHandle Handle to the smart object slot ( will be passed into the result ) .
* @ param SlotDefinition Smart Object slot definition to use for validation .
* @ param SlotTransform Transform of the slot .
* @ param SlotEntranceHandle Handle to specific entrance if just one entrance should be checked . ( Optional )
* @ param ResultFunc Callback called on each result
*/
2023-08-14 03:40:42 -04:00
static void QueryValidatedSlotEntranceLocationsInternal (
const UWorld * World ,
2023-08-10 07:02:20 -04:00
FSmartObjectValidationContext & ValidationContext ,
const FSmartObjectSlotEntranceLocationRequest & Request ,
const FSmartObjectSlotHandle SlotHandle ,
const FSmartObjectSlotDefinition & SlotDefinition ,
const FTransform & SlotTransform ,
const FSmartObjectSlotEntranceHandle SlotEntranceHandle ,
TFunctionRef < bool ( const FSmartObjectSlotEntranceLocationResult & ) > ResultFunc
2023-08-14 03:40:42 -04:00
) ;
2023-08-10 07:02:20 -04:00
2022-02-21 01:10:34 -05:00
/**
* Name of the Space partition class to use .
* Usage :
* [ / Script / SmartObjectsModule . SmartObjectSubsystem ]
* SpacePartitionClassName = / Script / SmartObjectsModule . < SpacePartitionClassName >
*/
2022-05-22 10:30:02 -04:00
UPROPERTY ( config , meta = ( MetaClass = " /Script/SmartObjectsModule.SmartObjectSpacePartition " , DisplayName = " Spatial Representation Structure Class " ) )
2022-02-21 01:10:34 -05:00
FSoftClassPath SpacePartitionClassName ;
2021-09-28 13:33:17 -04:00
2022-02-03 14:03:16 -05:00
UPROPERTY ( )
2022-02-21 01:10:34 -05:00
TSubclassOf < USmartObjectSpacePartition > SpacePartitionClass ;
2022-02-03 14:03:16 -05:00
2022-02-21 01:10:34 -05:00
UPROPERTY ( )
TObjectPtr < USmartObjectSpacePartition > SpacePartition ;
UPROPERTY ( )
TObjectPtr < ASmartObjectSubsystemRenderingActor > RenderingActor ;
2022-11-24 14:53:52 -05:00
UPROPERTY ( Transient )
FSmartObjectContainer SmartObjectContainer ;
TArray < TWeakObjectPtr < ASmartObjectPersistentCollection > > RegisteredCollections ;
2022-02-21 01:10:34 -05:00
2023-09-05 11:29:58 -04:00
/**
* A map of registered smart object handles to their associated runtime data .
* Client side Smart Object Subsystem ' s will only have runtime data
* for Smart Object Components who enable replication , but server subsystems will have all smart object
* data .
*/
2022-11-30 07:17:21 -05:00
UPROPERTY ( Transient )
2022-01-19 14:16:16 -05:00
TMap < FSmartObjectHandle , FSmartObjectRuntime > RuntimeSmartObjects ;
2022-11-30 07:17:21 -05:00
2022-03-16 03:47:02 -04:00
/** List of registered components. */
UPROPERTY ( Transient )
2022-08-18 15:08:49 -04:00
TArray < TObjectPtr < USmartObjectComponent > > RegisteredSOComponents ;
2022-03-16 03:47:02 -04:00
2022-10-10 12:00:30 -04:00
/** smart objects that attempted to register while no collection was being present */
UPROPERTY ( Transient )
TArray < TObjectPtr < USmartObjectComponent > > PendingSmartObjectRegistration ;
2022-01-19 14:16:16 -05:00
uint32 NextFreeUserID = 1 ;
2021-09-28 13:33:17 -04:00
2022-11-24 14:53:52 -05:00
bool bRuntimeInitialized = false ;
2023-09-05 11:29:58 -04:00
/** Returns true if this subsystem is running on the server. */
bool IsRunningOnServer ( ) const ;
2021-11-02 11:09:09 -04:00
2022-12-08 11:50:57 -05:00
# if WITH_EDITOR
bool bAutoInitializeEditorInstances = true ;
# endif // WITH_EDITOR
2022-11-24 14:53:52 -05:00
# if WITH_EDITORONLY_DATA
/** Set in OnWorldComponentsUpdated and used to control special logic required to build collections in Editor mode */
bool bIsPartitionedWorld = false ;
friend class ASmartObjectPersistentCollection ;
2023-02-02 18:43:13 -05:00
void PopulateCollection ( ASmartObjectPersistentCollection & InCollection ) const ;
2022-11-24 14:53:52 -05:00
/** Iteratively adds items to registered collections. Expected to be called in World Partitined worlds. */
void IterativelyBuildCollections ( ) ;
2023-02-02 18:43:13 -05:00
int32 GetRegisteredSmartObjectsCompatibleWithCollection ( const ASmartObjectPersistentCollection & InCollection , TArray < USmartObjectComponent * > & OutRelevantComponents ) const ;
2021-11-02 11:09:09 -04:00
/**
2022-11-24 14:53:52 -05:00
* Compute bounds from the given world
2021-11-02 11:09:09 -04:00
* @ param World World from which the bounds must be computed
*/
2022-11-24 14:53:52 -05:00
FBox ComputeBounds ( const UWorld & World ) const ;
2022-12-08 11:50:57 -05:00
# endif // WITH_EDITORONLY_DATA
2021-09-28 13:33:17 -04:00
# if WITH_SMARTOBJECT_DEBUG
public :
2021-11-02 11:09:09 -04:00
uint32 DebugGetNumRuntimeObjects ( ) const { return RuntimeSmartObjects . Num ( ) ; }
2022-01-19 14:16:16 -05:00
const TMap < FSmartObjectHandle , FSmartObjectRuntime > & DebugGetRuntimeObjects ( ) const { return RuntimeSmartObjects ; }
2022-03-16 03:47:02 -04:00
uint32 DebugGetNumRegisteredComponents ( ) const { return RegisteredSOComponents . Num ( ) ; }
2021-11-02 11:09:09 -04:00
2023-07-18 08:42:51 -04:00
UE_DEPRECATED ( 5.3 , " DebugGetRuntimeSlots() is not supported anymore, slots are accessed via object runtime instead. " )
const TMap < FSmartObjectSlotHandle , FSmartObjectRuntimeSlot > & DebugGetRuntimeSlots ( ) const
{
static TMap < FSmartObjectSlotHandle , FSmartObjectRuntimeSlot > Dummy ;
return Dummy ;
}
2021-11-02 11:09:09 -04:00
/** Debugging helper to remove all registered smart objects from the simulation */
2021-09-28 13:33:17 -04:00
void DebugUnregisterAllSmartObjects ( ) ;
2021-11-02 11:09:09 -04:00
/** Debugging helpers to add all registered smart objects to the simulation */
2021-09-28 13:33:17 -04:00
void DebugRegisterAllSmartObjects ( ) ;
2022-02-17 03:40:43 -05:00
/** Debugging helper to emulate the start of the simulation to create all runtime data */
void DebugInitializeRuntime ( ) ;
/** Debugging helper to emulate the stop of the simulation to destroy all runtime data */
void DebugCleanupRuntime ( ) ;
2021-09-28 13:33:17 -04:00
# endif // WITH_SMARTOBJECT_DEBUG
2022-03-18 12:31:49 -04:00
} ;