Rules as structs (strategies)
Many rules of the Pulse plugins are struct strategies: a base struct with virtual functions, and a list or a field that holds any struct derived from it (TInstancedStruct<FBase>), picked in the details panel. Conditions, costs and rewards of Pulse Foundation work this way, and so do the hit detectors, fire modes and respawn rules of the plugins. A struct is light, it saves with the asset, and C++ adds new kinds without touching the plugin.
Only C++ can derive from a struct. So every strategy base also gets a Blueprint entry: a struct <Base>_Blueprint that holds an instance of a Blueprint class and forwards to it. Designers derive a Blueprint from that class and pick it in the entry “Blueprint …” of any list of the base.
The Blueprint side: UPulseStrategyObject
UPulseStrategyObject (Strategies/PulseStrategyObject.h) is the base of every such Blueprint class (Abstract, Blueprintable, edit inline, instanced):
- Every entry holds its own instance, so its values are set per entry.
- While a function of the entry runs, Get World of the object returns the world of the call, also for instances inside assets that have no world of their own (
FWorldScope). - The condition, cost and reward objects of Pulse Foundation (
UPulseConditionObject,UPulseCostObject,UPulseRewardObject) derive from it.
Give your strategy base a Blueprint entry
For a base FMyHitDetector with virtual bool Detect(const FMyHitQuery& InQuery) const:
- The Blueprint class, with one BlueprintNativeEvent per function of the base:
UCLASS(Abstract, Blueprintable, EditInlineNew, DefaultToInstanced, CollapseCategories)
class UMyHitDetectorObject : public UPulseStrategyObject
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintNativeEvent, Category = "My|Combat")
bool Detect(const FMyHitQuery& Query) const;
};
- The entry, which forwards each function with
Pulse::Strategies::Call(a result, with the value for an entry without object) orPulse::Strategies::Run(no result):
USTRUCT(BlueprintType, meta = (DisplayName = "Blueprint Hit Detector", Category = "Blueprint"))
struct FMyHitDetector_Blueprint : public FMyHitDetector
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, Instanced, Category = "Hit Detector")
TObjectPtr<UMyHitDetectorObject> Detector;
virtual bool Detect(const FMyHitQuery& InQuery) const override
{
return Pulse::Strategies::Call(Detector.Get(), InQuery.World, false, [&InQuery](const UMyHitDetectorObject& InObject) { return InObject.Detect(InQuery); });
}
};
- A text for lists and cards:
Pulse::Strategies::GetEntryText(Object, Text)gives the text of the object, else the name of its class.
That is all: the entry shows in every picker of the base, under Blueprint, and the editor cards show it like the other entries.