NPC behavior and FindCreativeObjectsWithTag best practice

Working on migrating one of my projects from GetCreativeObjectsWithTag to FindCreativeObjectsWithTag after this weekend’s update.

I’m looking for some kind of best practice when setting up the relationship between a npc_behavior script and one, or many, creative_device(s).

Prior to the migration, I used a GetCreativeObjectsWithTag call from the npc_behavior script to find the correct creative_device using tags (Reference: https://dev.epicgames.com/documentation/en-us/uefn/verse-starter-template-1-creating-npc-behavior-in-unreal-editor-for-fortnite).

Given the new structure of the API, this does no longer work. How do I create a relationship between the npc_behavior and my creative_device(s)? From what I gather, there is no way (?) of calling methods in the npc_behavior script from the creative_device, so I still need to find a way to call find the creative_device from the npc_behavior setup.

Appreciate all the help from the masterminds out there. :slight_smile:

1 Like

You need to retrieve a creative device that’s placed in the map through the behavior, only native way to handle this would be through gameplay tags

Appreciate the reply.

That’s exactly how I did this prior to the latest update. :slight_smile:

However, the new FindCreativeObjectsWithTag method requires me to have a reference to the creative device and I’m trying to figure out how to pass that to the npc_behavior script.

Mb I was being dumb, you need to use a global singleton that you can access in Verse from anywhere somehow

However it’s worth mentioning that making a singleton will likely break your code soon as mentioned in this post: I came up with a way to make singletons in Verse - #3 by CosmicDanAU

this method doesn’t work anymore :+1: you need to use weak maps

Great stuff. Managed to resolve the issue based on your direction. Thanks!

For anyone else facing similar issues, I did the following (I imagine there might be cleaner ways to pull this off):

  1. Setup a weak map in the creative device required to be called from the npc_behavior.
    var GameManagerMap : weak_map(session, game_manager) = map{}
  2. Populate the weak_map in the OnBegin method of that creative_device:
    var currentSession : session = GetSession()
    if (set GameManagerMap[currentSession] = Self) {}
  3. Retrieve the creative device in the npc_behavior:
    var currentSession : session = GetSession()
    var GameManager: ?game_manager = false
    if (GameManagerProxy := GameManagerMap[currentSession]) { set GameManager = option{GameManagerProxy} }
3 Likes