GetCreativeObjectsWithTags

method
GetCreativeObjectsWithTags<native><public>(SearchCriteria: tag_search_criteria)<transacts>: []creative_object_interface

DEPRECATED - use `FindCreativeObjectsWithTag` instead. Returns an array containing creative objects which have tag(s) matching the specified `SearchCriteria`.

Module
/Fortnite.com/Devices
Declared in
Devices
Source
fortnite

Used in

AudioSystem / Audio Controller Device verse-source
SubscribeToButtons() : void =
        TaggedButtons := GetCreativeObjectsWithTags(audio_tags_module.audio_tag{})
        for (Object : TaggedButtons):
            if (Button := button_device[Object]):
                Button.InteractedWithEvent.Subscribe(OnButtonInteraction)

    # Handle button interaction
    OnButtonInteraction(Agent : agent) : void =
Utils / Tag Utils verse-source
# Has been replaced with the FindCreativeObjectsWithTags function in the tag_controller.verse

GetCreativeObjectsWithTags<public>(SearchTags: []tag, ?Device: ?creative_device = false) : []creative_object_interface =
    var ValidTaggedObjects: []creative_object_interface = array{}
    # It's best to pass in a device so we don't have to create a new one every time as this can be expensive
    var CreativeDevice : creative_device = creative_device{}
    if (HasDevice :=Device?):
        set CreativeDevice = HasDevice
    for (SearchTag : SearchTags):
        TagSearchCriteria := SearchTag
        TaggedObjects := CreativeDevice.FindCreativeObjectsWithTag(SearchTag)

        # Add the tagged objects to the list
        set ValidTaggedObjects += for: 
            TagIndex -> TaggedObject : TaggedObjects
        do:
            TaggedObject
    #Logger.Print("Found {ValidTaggedObjects.Length} objects with tag")
    return ValidTaggedObjects
NpcSystem / Npc Godo verse-source
if ( := Get[]):
        NPCLocation := (1).GetTransform().Translation
        
        # Find all creative objects with the specified tag
        TaggedObjects := GetCreativeObjectsWithTags(SearchCriteria)
        
        #var ClosestObjectDistance: float = 1000000.0 # Initialize with a large value
        var ClosestObject: ?creative_object_interface = false
        
        # Find the closest tagged object to the NPC
        for (TaggedObject : TaggedObjects):
            ObjectLocation := TaggedObject.GetTransform().Translation
            DistanceToObject := Distance(NPCLocation, ObjectLocation)
            if (DistanceToObject < MaxTagDistance):
                #set ClosestObjectDistance = DistanceToObject
                set ClosestObject = option{TaggedObject}
        
        # If a closest object is found
        if (InteractObject := ClosestObject?):
            # Navigate to the closest object
            NavigationTarget := MakeNavigationTarget(InteractObject.GetTransform().Translation)
            if(DebugAI?) then DebugNpc("Navigating {InteractObject.GetTransform().Translation} to the closest object with tag", ?Duration := AIDebugDrawTime, ?TextColor := NamedColors.CadetBlue)
            Logger.Print("{NPCName} - Navigating to {InteractObject.GetTransform().Translation} the closest object with tag")
            race:
                NavigateResult := Navigatable.NavigateTo(NavigationTarget, ?MovementType := movement_types.Walking, ?ReachRadius:=100.0, ?AllowPartialPath:=true )
                block:
                    Sleep(Timeout) # If we don't reach the object in (default 30) seconds, we should stop trying to reach it.
                    Logger.Print("{NPCName} - GoDo - Navigation to the closest object with tag failed, timeout", ?Level:=log_level.Warning)
                    if (DebugAI?) then DebugNpc("Navigation to the closest object with tag failed, timeout", ?Duration := AIDebugDrawTime, ?TextColor := NamedColors.Red)
            # Check if the navigation was successful
            if (NavigateResult = navigation_result.Reached):
                # Perform actions on the closest object
                race:
                    FocusOnObject := InFocus.MaintainFocus(InteractObject.GetTransform().Translation)
                    block:
                        Sleep(1.0)
                        sync:
                            # Play animation
                            #if (PlayAnimSeq):
                            PlayAnimation(PlayAnimSeq)