# Array/Map not referenced correctly across multiple classes

**URL:** <https://forums.unrealengine.com/t/array-map-not-referenced-correctly-across-multiple-classes/1932570>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, fortnite\
**Created:** [July 10, 2024, 7:33am UTC](https://forums.unrealengine.com/t/array-map-not-referenced-correctly-across-multiple-classes/1932570 "2024-07-10T07:33:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DoubleBGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/doublebgames/32/954900_2.png) [@DoubleBGames](https://forums.unrealengine.com/u/DoubleBGames)\
**Post date:** [July 10, 2024, 7:33am UTC](https://forums.unrealengine.com/t/array-map-not-referenced-correctly-across-multiple-classes/1932570/1 "2024-07-10T07:33:09Z")

</div>

Hello,  
I am running into this problem where an array or map created in one class is not properly referenced in other classes except of one.

This is the main\_manager (In the real world it would be the game\_manager):

```auto
using { /Fortnite.com/Devices }

main_manager := class(creative_device):

    ArrayManager : array_manager = array_manager{}
    MiddleManager : middle_manager = middle_manager{}

    OnBegin<override>()<suspends>:void=
        ArrayManager.InitArr()
        MiddleManager.ActivateCallManager()
        Print("TestArr in main_manager has Length of {ArrayManager.TestArr.Length}")

```

This calls the initialisation of the test array\_manager (Irl it would call a InitPlayer function in a player\_manager after the player spawned or something). This is what the array\_manager (Irl player\_manager) looks like:

```auto
array_manager := class():
    
    var TestArr : []int = array{}

    InitArr() : void =
        set TestArr = {1, 2, 3}
        Print("TestArr in array_manager has Length of {TestArr.Length}")

```

The main\_manager also calls the middle\_manager which I just use for further debugging to check where the reference fails:

```auto
middle_manager := class():
    
    CallManager : call_manager = call_manager{}
    ArrayManager : array_manager = array_manager{}

    ActivateCallManager() : void =
        CallManager.CallArr()
        Print("TestArr in middle_manager has Length of {ArrayManager.TestArr.Length}")

```

The middle\_manager invokes the call\_manager (Irl a team\_manager for example which references an array of all players from the player\_manager):

```auto
call_manager := class():
    
    ArrayManager : array_manager = array_manager{}

    CallArr() : void =
        for(Number : ArrayManager.TestArr):
            Print("Current Iteration is: {Number}")
        Print("TestArr in call_manager has Length of {ArrayManager.TestArr.Length}")

```

The test array is referenced correctly in the array\_manager ofc and the main\_manager but as soon as it comes to the middle and call\_manager the array is empty:  
 ![Screenshot (69)](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/9/7/1976a05a799d8e5bd21e33cf0818b97756611187.png)  
If somebody could help me on this it would be greatly appreciated! Thank you for your time!

---

<div class="post-metadata">

**Author:** ![ok\_studios](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ok\_studios](https://forums.unrealengine.com/u/ok_studios)\
**Post date:** [July 10, 2024, 10:26am UTC](https://forums.unrealengine.com/t/array-map-not-referenced-correctly-across-multiple-classes/1932570/2 "2024-07-10T10:26:40Z")

</div>

Hi.  
This is curious to me.

I was able to duplicate this. I don’t have a complete solution yet, but it is telling that the For expression is failing, which also confirms the array is returning as empty. I was just wondering when you create multiple instances of the array\_manager with the same name if that isn’t the problem. Wouldn’t that, in a sense, create null references? If an array is going to be referenced by multiple classes, I’m wondering if it wouldn’t be better to create a superclass and have the other classes inherit from the superclass, so there is no need to create so many instances with the same name.

---

<div class="post-metadata">

**Author:** ![ok\_studios](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ok\_studios](https://forums.unrealengine.com/u/ok_studios)\
**Post date:** [July 10, 2024, 10:45am UTC](https://forums.unrealengine.com/t/array-map-not-referenced-correctly-across-multiple-classes/1932570/3 "2024-07-10T10:45:55Z")

</div>

```auto
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

main_manager := class(creative_device):

   

    OnBegin<override>()<suspends>:void=
        ArrayManager: array_manager= array_manager:
        MiddleManager: middle_manager = middle_manager:
        ArrayManager.InitArr()
        MiddleManager.ActivateCallManager()
        Print("TestArr in main_manager has Length of {ArrayManager.TestArr.Length}")

array_manager := class():
    
    var TestArr : []int = array{1,2,3}

    InitArr() : void =
        Print("TestArr in array_manager has Length of {TestArr.Length}")

middle_manager := class(array_manager):
    
    CallManager : call_manager = call_manager{}

    ActivateCallManager() : void =
        CallManager.CallArr()
        Print("TestArr in middle_manager has Length of {TestArr.Length}")

call_manager := class(array_manager):
    
    CallArr() : void =
        for(Number : TestArr):
            Print("Current Iteration is: {Number}")
        Print("TestArr in call_manager has Length of {TestArr.Length}")
    # Runs when the device is started in a running game

```

So this works except the set array is taken out. I will have to look at this more later.

---

<div class="post-metadata">

**Author:** ![DoubleBGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/doublebgames/32/954900_2.png) [@DoubleBGames](https://forums.unrealengine.com/u/DoubleBGames)\
**Post date:** [July 10, 2024, 3:13pm UTC](https://forums.unrealengine.com/t/array-map-not-referenced-correctly-across-multiple-classes/1932570/4 "2024-07-10T15:13:50Z")

</div>

Thank you for your answer!  
Your solution works for me aswell. This is strange because even when the array is initialized with the set method (which is mendetory for what I am trying to do) it gets referenced correctly only by the main\_manager… I am curios what you can find out about this.

---

<div class="post-metadata">

**Author:** ![DoubleBGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/doublebgames/32/954900_2.png) [@DoubleBGames](https://forums.unrealengine.com/u/DoubleBGames)\
**Post date:** [July 12, 2024, 5:41am UTC](https://forums.unrealengine.com/t/array-map-not-referenced-correctly-across-multiple-classes/1932570/5 "2024-07-12T05:41:14Z")

</div>

Did you manage to find something?

---

<div class="post-metadata">

**Author:** ![DoubleBGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/doublebgames/32/954900_2.png) [@DoubleBGames](https://forums.unrealengine.com/u/DoubleBGames)\
**Post date:** [July 19, 2024, 5:59am UTC](https://forums.unrealengine.com/t/array-map-not-referenced-correctly-across-multiple-classes/1932570/6 "2024-07-19T05:59:13Z")

</div>

So I kinda solved it myself.  
The problem I encountered here is because of my misunderstanding of object oriented programming. If I reference a var (TestArr) of a class (ArrayManager) from another (like MiddleManager) verse creates a copy of some kind of the whole class (ArrayManager) and also of the var (TestArr) and because the var hasn’t ben initialized (InitArr() hasn’t been called) through the calling class (MiddleManager) yet it pickes up the empty var (TestArr).  
This is also the reason why the MainManager picked the TestArr up correctely because for this class the array got initialized. Bur ONLY for this class.  
So the soluion is to Initialize the array once in something like a GameManager and pass the array to every other function which needs it as a Parameter.  
This whole object oriented programming topic is hard to grasp for me but I am slowly getting the hang of it. The Problem is always in fornt of the screen…
