Gnarwailbrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
The GnarwailBrain component defines the decision-making logic for the Gnarwail NPC, determining its behavior in response to environmental conditions, leader presence, combat targets, and available food items. It coordinates movement, combat, trading, and tossing interactions using a behavior tree (BT) architecture. The brain integrates closely with components such as combat, follower, trader, eater, boatphysics, and inventoryitem to evaluate dynamic game state and select appropriate actions.
Dependencies & Tags
- Components used:
combat,follower,trader,eater,boatphysics,inventoryitem - Tags:
INLIMBO,outofreach,FX,fishmeat,oceanfish,_inventoryitem,walkableplatform,smallcreature,busy,jumping
Properties
The component does not define custom public properties in its constructor. Behavior configuration is handled via constants and function references passed to behavior nodes.
Main Functions
HasValidWaterTarget(inst)
- Description: Determines whether the Gnarwail has a valid combat target located on invalid ground (i.e., on a boat or directly on water), which is required for initiating or maintaining combat behavior.
- Parameters:
inst(Entity instance) — the Gnarwail entity. - Returns:
trueifinst.components.combat.targetexists, is not on valid ground, and combat is not in cooldown; otherwisefalse.
GetNearbyTossTarget(inst)
- Description: Searches for a nearby item that the Gnarwail can toss, provided it is not on passable terrain and does not possess excluded tags.
- Parameters:
inst(Entity instance). - Returns: A single item entity if found and
inst.ready_to_tossis true; otherwisenil.
TryToTossNearestItem(inst)
- Description: Initiates the toss state machine for the nearest valid toss target, optionally specifying the leader as the toss destination unless the item is oceanfish.
- Parameters:
inst(Entity instance). - Returns:
nil. Invokesinst.sg:GoToState("toss_pre", toss_data)if a target is found.
GetLeaderFollowPosition(inst)
- Description: Computes the target position for the Gnarwail to follow its leader, adjusting for whether the leader is on a platform, moving boat physics, or on open water.
- Parameters:
inst(Entity instance). - Returns: A
Vector3position ornilif no leader exists.
GetLeaderFollowDistance(inst)
- Description: Returns the maximum follow distance based on the leader’s platform speed. When the platform is moving fast, the Gnarwail follows much closer.
- Parameters:
inst(Entity instance). - Returns: A scalar distance (float). Returns
0.5when the leader’s platform speed squared exceedsTUNING.GNARWAIL.WALK_SPEED^2; otherwiseMAX_BOAT_FOLLOW_DIST.
ShouldLeashRun(inst)
- Description: Determines whether the Gnarwail should run (leash condition) when the leader’s platform speed is high.
- Parameters:
inst(Entity instance). - Returns:
trueif the leader’s platform speed squared is greater than or equal toGNARWAIL_WALK_SQ; otherwisefalse.
GetTrader(inst)
- Description: Scans for nearby players attempting to trade with the Gnarwail within
TRADE_DISTANCE. - Parameters:
inst(Entity instance). - Returns: A player entity if one is found attempting a trade action; otherwise
nil.
FindFoodAction(inst)
- Description: Finds and returns a buffered eat action for a nearby edible item that has been in the world for at least 3 seconds and is not held or on passable terrain.
- Parameters:
inst(Entity instance). - Returns: A
BufferedActionobject if conditions are met; otherwisenil.
GetWanderDirection(inst)
- Description: Computes a wander direction opposite to the nearest boat if the Gnarwail is near one, using a randomized angular offset.
- Parameters:
inst(Entity instance). - Returns: An angle in radians or
nilif no nearby boat is found.
GetFollowTargetFn(inst)
- Description: Returns the current combat target if it exists, is not small, and the Gnarwail is not jumping.
- Parameters:
inst(Entity instance). - Returns: Entity target or
nil.
KeepFaceTargetFn(inst)
- Description: Returns
trueif the current combat target is on water (invalid ground), prompting the Gnarwail to face the target while following. - Parameters:
inst(Entity instance). - Returns:
trueorfalse.
GnarwailBrain:OnStart()
- Description: Initializes the behavior tree root node with priority-based decisions handling horn-breaking panic, electric fences, combat, leashing, trading, eating, tossing, and wandering. Each condition is evaluated periodically by the behavior tree.
- Parameters: None.
- Returns: None. Constructs and assigns
self.btwith the rootBTnode.
Events & Listeners
The GnarwailBrain component does not register or fire events directly. It relies on the state graph’s event handling and the behavior tree’s periodic evaluation of predicates.