# NPC behavior and FindCreativeObjectsWithTag best practice

**URL:** <https://forums.unrealengine.com/t/npc-behavior-and-findcreativeobjectswithtag-best-practice/2107457>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [November 6, 2024, 7:54am UTC](https://forums.unrealengine.com/t/npc-behavior-and-findcreativeobjectswithtag-best-practice/2107457 "2024-11-06T07:54:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zoakibo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zoakibo](https://forums.unrealengine.com/u/zoakibo)\
**Post date:** [November 6, 2024, 7:54am UTC](https://forums.unrealengine.com/t/npc-behavior-and-findcreativeobjectswithtag-best-practice/2107457/1 "2024-11-06T07:54:40Z")

</div>

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](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. 🙂

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [November 6, 2024, 1:45pm UTC](https://forums.unrealengine.com/t/npc-behavior-and-findcreativeobjectswithtag-best-practice/2107457/2 "2024-11-06T13:45:36Z")

</div>

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~~

---

<div class="post-metadata">

**Author:** ![zoakibo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zoakibo](https://forums.unrealengine.com/u/zoakibo)\
**Post date:** [November 6, 2024, 8:38pm UTC](https://forums.unrealengine.com/t/npc-behavior-and-findcreativeobjectswithtag-best-practice/2107457/3 "2024-11-06T20:38:18Z")

</div>

Appreciate the reply.

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

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.

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [November 7, 2024, 8:30am UTC](https://forums.unrealengine.com/t/npc-behavior-and-findcreativeobjectswithtag-best-practice/2107457/4 "2024-11-07T08:30:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tonkatron8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tonkatron8](https://forums.unrealengine.com/u/Tonkatron8)\
**Post date:** [November 7, 2024, 9:34am UTC](https://forums.unrealengine.com/t/npc-behavior-and-findcreativeobjectswithtag-best-practice/2107457/5 "2024-11-07T09:34:09Z")

</div>

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](https://forums.unrealengine.com/t/i-came-up-with-a-way-to-make-singletons-in-verse/1139453/3)

> [@I came up with a way to make singletons in Verse](https://forums.unrealengine.com/t/i-came-up-with-a-way-to-make-singletons-in-verse/1139453/4):
>
> Unfortunately, there is a reason why we don’t let you declare a global `var`: we’re not done implementing global variables, and want to reserve the right to change their behavior without breaking everybody’s code, so for now we disallow them.
> 
> We recently discovered this particular loophole ourselves, and are in the process of closing it. I recommend against using it in the meantime, as once we close the loophole, your code won’t compile.

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [November 7, 2024, 11:20am UTC](https://forums.unrealengine.com/t/npc-behavior-and-findcreativeobjectswithtag-best-practice/2107457/6 "2024-11-07T11:20:42Z")

</div>

this method doesn’t work anymore 👍 you need to use weak maps

---

<div class="post-metadata">

**Author:** ![zoakibo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zoakibo](https://forums.unrealengine.com/u/zoakibo)\
**Post date:** [November 7, 2024, 9:19pm UTC](https://forums.unrealengine.com/t/npc-behavior-and-findcreativeobjectswithtag-best-practice/2107457/7 "2024-11-07T21:19:29Z")

</div>

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} }`
