# Can we get data from a class into another class?

**URL:** <https://forums.unrealengine.com/t/can-we-get-data-from-a-class-into-another-class/1166094>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [May 15, 2023, 5:55am UTC](https://forums.unrealengine.com/t/can-we-get-data-from-a-class-into-another-class/1166094 "2023-05-15T05:55:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![2GHSamburskoy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@2GHSamburskoy](https://forums.unrealengine.com/u/2GHSamburskoy)\
**Post date:** [May 15, 2023, 5:55am UTC](https://forums.unrealengine.com/t/can-we-get-data-from-a-class-into-another-class/1166094/1 "2023-05-15T05:55:04Z")

</div>

How can we get a value from another class?

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

Test := class<unique>(creative_device):

    var PlayerIntMap : [player]int = map{}
    TestClass2 : Test2 = Test2{}

    OnBegin<override>()<suspends>:void=
        if:
            Player := GetPlayspace().GetPlayers()[0]
            set PlayerIntMap[Player] = 777
        then:
            #sucess set
            TestClass2.A(Player) #success call

    ReturnMap():[player]int=
        return PlayerIntMap
    
    ReturnInt(Player : player):int=
        var IntValue : int = 0
        if:
            PlayerInt := PlayerIntMap[Player]
            set IntValue = PlayerInt
        return IntValue

Test2 := class(): #not creative_device

    @editable TestClass : Test = Test{}

    A(Player : player):void=
        if(PlayerInt := TestClass.PlayerIntMap[Player]):
            #nothing

        if(PlayerInt := Test{}.PlayerIntMap[Player]):
            #nothing

        TestInstance := Test{}
        if(PlayerInt := TestInstance.PlayerIntMap[Player]):
            #nothing
        
        NewInstanceMap := TestClass.PlayerIntMap
        if(PlayerInt := NewInstanceMap[Player]):
            #nothing

        NewInstanceMap2 := TestClass.ReturnMap()
        if(PlayerInt := NewInstanceMap2[Player]):
            #nothing

        PlayerIntF := TestClass.ReturnInt(Player)
        Print("{PlayerIntF}")
        #nothing
        

```

---

<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:** [May 15, 2023, 8:59am UTC](https://forums.unrealengine.com/t/can-we-get-data-from-a-class-into-another-class/1166094/2 "2023-05-15T08:59:22Z")

</div>

The problem with your attempt is that the `Test2` object doesn’t access the good `Test` object.

```auto
@editable TestClass : Test = Test{} # Here you're creating a new Test object using its constructor, so the functions are usable but
# they won't return any data you've set in your code above

```

Ok so basically I think of 3 ways to do this :

- You give a reference to your TestClass (device) when initializing your Test2 class, like this :

```auto
Test2 := class():
    MyDevice:Test

Test := class<unique>(creative_device):
    var TestClass2 : ?Test2 = false

    OnBegin<override>()<suspends> : void =
        set TestClass2 = option{Test2{MyDevice := Self}}

```

Now your Test2 class has a link to your Test device and your functions are working, you just need to unwrap your TestClass2 everytime (surely there’s a bit cleaner way to do it)

- You try to implement singletons as described in [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)  
This solution is cleaner if you’re gonna have lots of classes each connected to eachother.

- You make your Test2 a device too, and with @editable attribute you assign both the Test and Test2 to eachother inside UEFN.

---

<div class="post-metadata">

**Author:** ![devintly](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@devintly](https://forums.unrealengine.com/u/devintly)\
**Post date:** [February 19, 2024, 3:41pm UTC](https://forums.unrealengine.com/t/can-we-get-data-from-a-class-into-another-class/1166094/3 "2024-02-19T15:41:20Z")

</div>

Hello how is the situation right now? When i try to connect two verse devices to each other with @editable, uefn crashes

---

<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:** [February 19, 2024, 4:33pm UTC](https://forums.unrealengine.com/t/can-we-get-data-from-a-class-into-another-class/1166094/4 "2024-02-19T16:33:16Z")

</div>

You have an infinite loop issue, you should try linking them using optionals : `@editable MyDeviceMaybe : ?my_device = false`

---

<div class="post-metadata">

**Author:** ![KyleWebDev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KyleWebDev](https://forums.unrealengine.com/u/KyleWebDev)\
**Post date:** [September 5, 2024, 2:50pm UTC](https://forums.unrealengine.com/t/can-we-get-data-from-a-class-into-another-class/1166094/5 "2024-09-05T14:50:29Z")

</div>

THANK YOU, YOU ARE THE GOAT.

Really though, as a beginner this was something I was seriously struggling with!

Thank you so much! This example should be put directly in the docs for how to handle passing of data between classes.
