NsSynapse is a Utility AI. An agent has a list of actions. Each action has considerations that give a score from 0 to 1. The agent picks the action with the highest combined score and runs it.
Use it for agents that weigh many factors, such as health, distance, and ammo. Do not use it for path finding, perception, or animation. It does not replace a Behavior Tree for long, ordered tasks.
NsSynapse folder into the Plugins folder of your project."NsSynapse" to the dependencies of your game module in its Build.cs.The plugin needs no project settings. Its module runs on Win64, Mac, and Linux.
NsSynapseConsideration.Calculate Score. Return a value from 0 to 1.NsSynapseAction.Execute Action. Put the behavior there.Think And React on the component, for example from a timer.#include "Classes/NsSynapseBrainComponent.h"
#include "Classes/NsSynapseConsideration.h"
// A consideration that prefers low health
UCLASS()
class UMyLowHealthConsideration : public UNsSynapseConsideration
{
GENERATED_BODY()
public:
virtual float CalculateScore_Implementation(AActor* const InOwner) const override
{
const AMyBot* const Bot = Cast<AMyBot>(InOwner);
return Bot != nullptr ? 1.f - Bot->GetHealthPercent() : 0.f;
}
};
// Decide and act
Brain->ThinkAndReact();
Think on the brain component.Get Best Action.Set Busy with true when a long action starts.Set Busy with false when the action ends.Think And React does nothing while the brain is busy. Think does not read the busy flag.
Choose Action with the array.Get Best Action to read the result.Calculate Score or Execute Action to your actor class.The input is the owner of the brain component.
| Setting | Default | Effect |
|---|---|---|
| Possible Actions | Empty | The action classes that Think and Think And React score. |
| Best Action | None | Read only. The action from the last choice. |
| Busy | false | Read only in the Details panel. While true, Think And React does nothing. Change it with Set Busy. |
| Setting | Default | Effect |
|---|---|---|
| Considerations | Empty | The consideration classes that score this action. With no considerations, the action scores 1. |
| Setting | Default | Effect |
|---|---|---|
| Consideration Curve | Line from (0, 0) to (1, 1) | Maps the raw score to the final score. |
Score Action on one action to read its score.Get Score on an action to read the last score that a brain stored on it.NsSynapse has no console commands, CVars, debug draw, or log category.
| Problem | Cause | Fix |
|---|---|---|
| No action runs | All actions score 0, so Best Action is null. | Make sure that at least one consideration returns more than 0. |
| No action runs | The brain is busy. | Call Set Busy with false when the last action ends. |
| An action always wins | The action has no considerations, so it scores 1. | Add considerations to the action. |
| Data from one agent shows on another | All agents share the class default object of each action. | Keep per-agent data on the actor, not on the action. |
| The score ignores a value above 1 | The plugin clamps the raw score to 0..1. | Return a normalized value from Calculate Score. |
Get Score on an action returns the last score from any agent, because the CDO is shared.Think or Think And React.