-
Notifications
You must be signed in to change notification settings - Fork 0
KLEP Neurons
The Neuron acts as a holder of keys and a discoverer of behaviors. It manages all setup on Awake, making setting up and cloning AI agents incredibly simple.
When you assign a neuron to a GameObject, any KLEP behaviors (executables) that are children of that object are automatically discovered on awake.
In large and complex hierarchies, KLEPNeuron automatically discovers all executables that are children of the assigned GameObject. This behavior is powerful but can lead to performance and management challenges if your hierarchy is deeply nested or contains many executables.
- Instead of allowing KLEPNeuron to recursively search all children, you can specify a dedicated parent object to contain only the relevant executables.
- This reduces overhead and improves performance, especially in large scenes or with complex agent setups.
-
Create a Parent Object:
- Make an empty GameObject called "KLEPBehaviors" or similar.
-
Organize Executables:
- Add all KLEPExecutables as children of this parent object.
-
Assign Parent to KLEPNeuron:
- In the Unity Editor, set the parent object as the behavior holder for the KLEPNeuron.
-
Code Example:
public Transform behaviorParent;
void UpdateCurrentFrameExecutables()
{
HashSet<KLEPExecutableBase> newFrameExecutables = new HashSet<KLEPExecutableBase>();
if (behaviorParent != null)
{
GatherExecutables(behaviorParent, newFrameExecutables);
}
else
{
GatherExecutables(transform, newFrameExecutables);
}
SynchronizeExecutables(newFrameExecutables);
}
For small prototypes or simple AI agents, the default behavior is fine.
For large-scale projects, use a dedicated parent object to keep behavior management clean and organized.
- Provides a clear strategy for managing large hierarchies.
- Shows how to optionally set a parent object for behavior discovery.
- Uses a code example to illustrate how to implement this approach.
Would you like help with additional code examples, or are you looking to expand on specific scenarios where this parent object approach would be most useful? 😊
void Update()
{
bridge.UniversalEvent("BeforeCleanup");
keyManager.Cleanup();
UpdateCurrentFrameExecutables();
keyManager.IssueBufferedKeys();
bridge.BridgeUpdate();
agent.AgentUpdate();
bridge.UniversalEvent("AfterKeyBufferRelease");
fixedUpdateKeys = heldKeys;
}
🛠️ Step-by-Step Breakdown:
Cleanup Keys:
Starts by cleaning up all keys used in the last frame.
Discover New Executables:
Finds out if new executables have been acquired by the neuron.
Issue Buffered Keys:
Issues keys that were pushed to the buffer in the previous frame.
Update the Bridge:
Tells the bridge (a custom event-driven architecture) to update.
Update the Agent:
The agent updates, which is where all executables fire.
Notify Completion:
The bridge is notified that execution is complete, allowing listeners to react.
Update Fixed Keys:
Fixed update keys are updated to reflect the current neuron's keys.
⚖️ Update vs. Fixed Update:
The neuron operates in a normal update cycle, running as fast as the machine allows.
However, some executables may need to operate on fixed time (physics-related logic).
KLEP supports executables firing on either or both update cycles, offering flexibility for your AI logic.
🚀 Why This Matters:
Everything is automated—just add a child object to the agent, and if that object has an executable, it will be:
Incorporated at the start of the next frame.
Immediately available for the agent to use in traversing problem space.
This dynamic discovery and execution allow KLEP agents to adapt in real-time, giving your AI the tools to respond to changing scenarios seamlessly.