using { /Fortnite.com/AI } using { /Fortnite.com/Characters } using { /Fortnite.com/Playspaces } using { /Verse.org/Simulation } using { /Verse.org/SceneGraph } using { /UnrealEngine.com/Temporary/Diagnostics } # SIDEKICK COMPANION — a pet that follows you and emotes how it feels. # # Sidekicks are NPC companions with their own moods and reactions. You spawn one # from an NPC Spawner using a Sidekick character definition, then drive it with # an npc_behavior. The Sidekick API lives on the npc_sidekick_component, which # you read off the behavior's ENTITY (GetEntity[].GetComponent[...]). # # This companion locks onto its owner, follows them around, and plays a Happy # reaction the moment it catches up — then forces a permanent cheerful mood so # it never sulks. You cannot BUILD a sidekick_component in Verse (it's # epic_internal), but once the spawner gives you one, every method here is public. sidekick_companion := class(npc_behavior): # How close the pet tries to get to its owner (centimeters). FollowRadius : float = 300.0 OnBegin() : void = if: Agent := GetAgent[] Character := Agent.GetFortCharacter[] Entity := GetEntity[] # Pull the sidekick component off our own entity. Sidekick := Entity.GetComponent[npc_sidekick_component] then: Print("Sidekick reporting for duty!") # Lock it into a cheerful mood and react to its own mood swings. set Sidekick.MoodOverride = option{ sidekick_mood.Neutral } Sidekick.ChangeMoodEvent.Subscribe(OnMoodChanged) # Find a player to adopt as our owner, then follow forever. if (Owner := FindOwner[Entity]): spawn{ FollowOwner(Character, Owner, Sidekick) } # Grab the first player in the match as the companion's owner. We reach the # playspace through our own entity (npc_behavior.GetPlayspace is epic_internal). FindOwner(Entity : entity) : agent = Playspace := Entity.GetPlayspaceForEntity[] Players := Playspace.GetPlayers() Players[0] # Chase the owner forever, celebrating each time we reach them. FollowOwner(Character : fort_character, Owner : agent, Sidekick : npc_sidekick_component) : void = if (Navigatable := Character.GetNavigatable[]): loop: Target := MakeNavigationTarget(Owner) Result := Navigatable.NavigateTo(Target, ?ReachRadius := FollowRadius) if (Result = navigation_result.Reached): # Caught up — play a happy emote (failable: may be busy). if (Sidekick.PlayReaction[sidekick_reaction.Happy]): Print("Sidekick caught up — playing Happy!") Navigatable.Wait(?Duration := 1.5) # Log mood transitions so you can see the system tick. OnMoodChanged(Moods : tuple(sidekick_mood, sidekick_mood)) : void = Print("Sidekick mood changed.")