Navigation
API > API/Plugins > API/Plugins/WorldConditions
Base struct for all World Conditions.
World Conditions are used together with World Condition Query to create expressions of conditions whose result can be checked. The conditions can be based on globally accessible data (e.g. subsystems), or based on any of the context data accessible via FWorldConditionContext. The data that is available is defined for each use case using a UWorldConditionSchema. It also defines which conditions are available when creating a query in that use case.
FWorldConditionContextDataRef allows to reference a specific context data. When added on a world condition as property, the UI allows to pick context data of specified type, and in code, pointer to the actual data can be accessed via the context.
FWorldConditionContextDataRef BarRef;
FWorldConditionResult FWorldConditionFoo::IsTrue(const FWorldConditionContext& Context) const
{
if (FStructBar* Bar = Context.GetMutableContextDataPtr
Under the hood a reference is a name that needs to be turned into an index before use. This is done on Initialize(): bool FWorldConditionFoo::Initialize(const UWorldConditionSchema& Schema)
{
if (!Schema.ResolveContextDataRef
To speed up query evaluation, the result of a World Condition can be cached by World Condition Query. A result can be cached, if the condition is based on globally accessible data, or context data that is marked as Permanent. Context data marked as Dynamic may change each time IsTrue() is called and the result should never be cached.
To indicate that a result can be cached it should have bCanBeCached set to true when returned by IsTrue().
In cases where a data change callback can be registered based on context data, the caching can be determined during Initialize() by checking of the referenced data is persistent: bool FWorldConditionFoo::Initialize(const UWorldConditionSchema& Schema) { ... bCanCacheResult = Schema.GetContextDataTypeByRef(BarRef) == EWorldConditionContextDataType::Persistent) ... }
The caching status is returned from IsTrue() along with the result: FWorldConditionResult FWorldConditionFoo::IsTrue(const FWorldConditionContext& Context) const { FWorldConditionResult Result(EWorldConditionResult::IsFalse, bCanCacheResult); ... return Result; }
When the result is cached, it needs to be invalidated when new value arrives. This can be done using e.g. a delegate callback and invalidation handle. The call to InvalidateResult() on that handle will invalidate the query state so that next time IsTrue() is called required conditions will be re-evaluated. It is advised to do as little work as possible in the delegate callback: bool FWorldConditionFoo::Activate(const FWorldConditionContext& Context) const
{
FStructBar* Bar = Context.GetMutableContextDataPtr
Note that bCanCacheResult is stored in the condition inside world condition definition, and is the same for all instances of the world condition query state. Sometimes the caching status also relies on the input data, say, a condition may operate with a component or interface of a given actor, one of which may not have invalidation callbacks. In such case we can use some data in the condition state to decide the caching status of the result when returning it from IsTrue():
FWorldConditionResult FWorldConditionFoo::IsTrue(const FWorldConditionContext& Context) const { FStateType& State = Context.GetState(*this);
// Only cache result if we were able to register invalidation callback const bool bResultCanBeCached = State.DelegateHandle.IsValid(); FWorldConditionResult Result(EWorldConditionResult::IsFalse, bResultCanBeCached);
if (FStructBar* Bar = Context.GetMutableContextDataPtr
return Result; }
| Name | FWorldConditionBase |
| Type | struct |
| Header File | /Engine/Plugins/Runtime/WorldConditions/Source/WorldConditions/Public/WorldConditionBase.h |
| Include Path | #include "WorldConditionBase.h" |
Syntax
USTRUCT (Meta=(Hidden))
struct FWorldConditionBase
Derived Classes
FWorldConditionBase derived class hierarchy
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
FWorldConditionBase() |
WorldConditionBase.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual ~FWorldConditionBase() |
WorldConditionBase.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual bool Activate
(
const FWorldConditionContext& Context |
Called to activate the condition. | WorldConditionBase.h | |
virtual void Deactivate
(
const FWorldConditionContext& Context |
Called to deactivate the condition. | WorldConditionBase.h | |
uint8 GetConditionIndex() |
WorldConditionBase.h | ||
virtual FText GetDescription() |
WorldConditionBase.h | ||
uint8 GetNextExpressionDepth() |
WorldConditionBase.h | ||
EWorldConditionOperator GetOperator() |
WorldConditionBase.h | ||
virtual TObjectPtr< const UStruct > * GetRuntimeStateType() |
WorldConditionBase.h | ||
uint16 GetStateDataOffset() |
WorldConditionBase.h | ||
virtual bool Initialize
(
const UWorldConditionSchema& Schema |
Initializes the condition to be used with a specific schema. | WorldConditionBase.h | |
bool IsStateObject() |
WorldConditionBase.h | ||
virtual FWorldConditionResult IsTrue
(
const FWorldConditionContext& Context |
Called to check the condition state. | WorldConditionBase.h | |
bool ShouldInvertResult() |
WorldConditionBase.h |