Assign creatures to AI Path : Need help

I am trying to use a creature_place_device which spawns a creature at runtime, then when spawned the creature should run along a patrolling path which has been added yet it ignores it and always goes after the player. Is there any way to override this creature’s behaviour? Is there a way to do AI pathing for any AI or just agents?

I have been using the verse code from the stronghold project and tried to modify it for my application.

Code below:

using { /Fortnite.com/AI }
using { /Fortnite.com/Characters }
using { /Fortnite.com/Devices }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /Verse.org/Colors }
using { /Verse.org/Random }
using { /Verse.org/Simulation }

Visit here to create a verse device.

A Verse-authored creative device that can be placed in a level

npc_spawner_device_example := class(creative_device):

# Reference to the NPC Spawner Device in the level.
# In the Details panel for this Verse device,
# set this property to your NPC Spawner Device.
@editable
Creature1: creature_placer_device = creature_placer_device{}

@editable
CreatureSpawners: []creature_placer_device := array{}

@editable
MyZombieManagerDevice:creature_manager_device = creature_manager_device{}

@editable
PatrolPaths:[]ai_patrol_path_device := array{}

# Set the leash inner radius. This value must be in centimeters. 
# This defines the volume that must be reached when this leash is assigned to guards
@editable 
LeashInnerRadius<private>:float = 2300.0

# Set the leash outer radius. This value must be in centimeters
# This defines the volume in which guards must stay in when this leash is assigned
@editable
LeashOuterRadius<private>:float = 2400.0

var<private> Creatures : []agent = array{}


# Runs when the device is started in a running game.
OnBegin<override>()<suspends>:void=


    # Example for subscribing to an event on the Creative device.
    # Signaled when a character is spawned from the NPC Spawner Device.
    # Sends the `agent` character who was spawned.
    #Creature1.SpawnedEvent.Subscribe(OnCreatureSpawned)


    # Signaled when a character Spawned from the NPC Spawner Device is
    # eliminated. Sends a device_ai_interaction_result of the agent who eliminated
    # the character, and
    Creature1.EliminatedEvent.Subscribe(OnCreatureEliminated)

    MyZombieManagerDevice.Enable()

    for (CreatureSpawner : CreatureSpawners):
        CreatureSpawner.Spawn()
        CreatureSpawner.SpawnedEvent.Subscribe(ApplyLeashOnCreature)
        #PatrolPaths.Assign(Creatures:Creature)
        

    for (PatrolPath : PatrolPaths):
        PatrolPath.PatrolPathStartedEvent.Subscribe(PatrolPathStarted)
        PatrolPath.PatrolPathStoppedEvent.Subscribe(PatrolPathStopped)


# This function runs when a character is spawned from the NPC Spawner
# because it's an event handler for SpawnedEvent.
OnCharacterSpawned(SpawnedAgent:agent):void=


    Print("A character just spawned from this device.")


    # When a character spawns, have them focus on the first player in the playspace
    if:
        FortCharacter := SpawnedAgent.GetFortCharacter[]
        FocusInterface := FortCharacter.GetFocusInterface[]
        PlayerToFocus := GetPlayspace().GetPlayers()[0]
    then:
        spawn{FocusInterface.MaintainFocus(PlayerToFocus)}


# This function runs when the character spawned from the NPC Spawner
# is eliminated, because it's an event handler for EliminatedEvent.
OnCharacterEliminated(AIInteractionResult:device_ai_interaction_result):void=


    # `Source` is the `agent` that has eliminated the creature.
    # If the creature was eliminated by a non-agent then `Source` is 'false'.
    # `Target` is the creature that was eliminated.
    if(AIInteractionResult.Source?):
        Print("The character was eliminated by another agent.")
    else:
        Print("The character was not eliminated by another agent.")

OnCreatureEliminated(Agent:?agent):void=
    Print("Yay here is our elimination function", ?Duration:=6.0)
    if(EliminatingAgent := Agent?):
        if (PlayerObj := player[EliminatingAgent]):
            #if(CustomPlayer:CustomPlayer = PlayersMap[PlayerObj]):
                #CustomPlayer.AddSuperBucks(EliminationValue)


ApplyLeashOnCreature(Creature:agent):void=
    #Log("Leash position - Applying leash {LeashInnerRadius} / {LeashOuterRadius} on creature")
    if (Leashable:=Creature.GetFortCharacter[].GetFortLeashable[]):
        Leashable.SetLeashPosition(GetTransform().Translation, LeashInnerRadius, LeashOuterRadius)

        set Creatures += array{Creature}

PatrolPathStarted(Agent:agent):void=
    if:
        Creatures.Find[Creatures]
        Leashable:=Agent.GetFortCharacter[].GetFortLeashable[]
    then:
        #Log("Leash position - Patrol started - Clearing leash {LeashInnerRadius} / {LeashOuterRadius} on guard")
        Leashable.ClearLeash()

PatrolPathStopped(Agent:agent):void=
    if:
        Creatures.Find[Creatures]
        Leashable:=Agent.GetFortCharacter[].GetFortLeashable[]
    then:
        #Log("Leash position - Patrol stopped - Setting leash {LeashInnerRadius} / {LeashOuterRadius} on guard")
        Leashable.SetLeashPosition(GetTransform().Translation, LeashInnerRadius, LeashOuterRadius)

Unfortunately, at least as of now, it seems like AI Paths only apply to the guard spawner: AI Patrol Path Node Devices

1 Like

Thanks for the reply. I hope they will add it sometime. Would open up sooo many new possibilities