# Blocker - Custom device's local variables are reset when called from another device.

**URL:** <https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865>\
**Category:** Issues and Bug Reporting\
**Tags:** unreal-editor-for-fortnite, fortnite\
**Created:** [February 8, 2023, 11:34pm UTC](https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865 "2023-02-08T23:34:38Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![DustinREDGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dustinredgames/32/634988_2.png) [@DustinREDGames](https://forums.unrealengine.com/u/DustinREDGames)\
**Post date:** [February 8, 2023, 11:34pm UTC](https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865/1 "2023-02-08T23:34:38Z")

</div>

- Device1 changes a local variable in OnBegin or anytime.
- From a trigger callback, Device2 calls a method on Device1.
- In the Device1’s method, the local variable is now reset to default values.

**Can a custom device not reference another custom device?**  
Its almost as if Device2 has a completely different instance reference of Device1.

Is this not the proper way to do something like this?

This seems like a major bug when trying to communicate between custom devices and is currently a major blocker for us.

Output log:

```auto
LogVerse: log_test1_device: ----------------
LogVerse: log_test1_device: _testfloat: 0.123457
LogVerse: log_test1_device: _testfloat: 0.000000

```

Example Device1:

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

log_test1_device := class(log_channel){}

test1_device := class(creative_device):
    Logger:log = log{Channel:=log_test1_device}

    var _testfloat:float = 0.0

    OnBegin<override>()<suspends>:void=
        set _testfloat = 0.123456789
        Logger.Print("----------------")
        Logger.Print("_testfloat: {_testfloat}")

    TestCall():void=
        Logger.Print("_testfloat: {_testfloat}")

```

Example Device 2:

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

test2_device := class(creative_device):

    @editable
    Test1Device : test1_device = test1_device{}

    @editable
    TestTrigger : trigger_device = trigger_device{}

    OnBegin<override>()<suspends>:void=
        TestTrigger.TriggeredEvent.Subscribe(OnTriggeredEvent)

    OnTriggeredEvent(Player:player):void=
        Test1Device.TestCall()

```

---

<div class="post-metadata">

**Author:** ![Rory\_REDGamesCo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rory_redgamesco/32/634990_2.png) [@Rory\_REDGamesCo](https://forums.unrealengine.com/u/Rory_REDGamesCo)\
**Post date:** [February 9, 2023, 2:59pm UTC](https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865/2 "2023-02-09T14:59:32Z")

</div>

I am also seeing this. With one device that randomly sets an int on trigger and prints it on another trigger it works fine. When I add a second device that calls print via its own trigger all the values are default.

```auto

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using {/Verse.org/Random }
using { /EpicGames.com/Temporary/Diagnostics }

simple_data_device := class(creative_device)
{
    @editable DisplayValueTrigger:trigger_device = trigger_device{}
    @editable SetRandomValueTrigger:trigger_device = trigger_device{}

    var Value:int = -1
    OnBegin<override>()<suspends>:void=
    {
        DisplayValueTrigger.TriggeredEvent.Subscribe(OnDisplayData)
        SetRandomValueTrigger.TriggeredEvent.Subscribe(OnSetDataRandomly)
    }

    OnSetDataRandomly(TriggerPlayer:player):void=
    {
        set Value = GetRandomInt(0, 100);
        Print("Set Value: {Value}")  
    }

    OnDisplayData<public>(TriggerPlayer:player):void=
    {
        Print("Current Value: {Value}")    
    }
}

    

```

Second device referencing this one.

```auto

using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /EpicGames.com/Temporary/Diagnostics }

simple_secondary_device := class(creative_device)
{
    @editable 
    SimpleDataDevice:simple_data_device=simple_data_device{}

    @editable DisplayValueSecondaryTrigger:trigger_device = trigger_device{}

    OnBegin<override>()<suspends>:void=
    {
        DisplayValueSecondaryTrigger.TriggeredEvent.Subscribe(OnDisplayDataSecondary)
    }

    OnDisplayDataSecondary<public>(TriggerPlayer:player):void=
    {
        Print("Calling DisplayData Through Secondary Device...")
        SimpleDataDevice.OnDisplayData(TriggerPlayer)     
    }
}

    

```

---

<div class="post-metadata">

**Author:** ![Flak](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/flak/32/769441_2.png) [@Flak](https://forums.unrealengine.com/u/Flak)\
**Post date:** [February 9, 2023, 3:59pm UTC](https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865/3 "2023-02-09T15:59:39Z")

</div>

Thanks both, our team is taking a look.

---

<div class="post-metadata">

**Author:** ![Tom.Noonan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tom.Noonan](https://forums.unrealengine.com/u/Tom.Noonan)\
**Post date:** [February 16, 2023, 9:17am UTC](https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865/4 "2023-02-16T09:17:39Z")

</div>

While waiting for this fix to reach release it should be possible to workaround this issue by using a one element array rather than the direct reference.

Could you try changing your code from

```
@editable
Test1Device : test1_device = test1_device{}

```

To:

```
@editable
Test1Device : []test1_device = array{}

```

and adding a single element with the device reference in the editor.

---

<div class="post-metadata">

**Author:** ![DustinREDGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dustinredgames/32/634988_2.png) [@DustinREDGames](https://forums.unrealengine.com/u/DustinREDGames)\
**Post date:** [February 16, 2023, 3:42pm UTC](https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865/5 "2023-02-16T15:42:22Z")

</div>

This temp fix works, thank you!

Our current fix has been to use trigger devices as a way to signal events between custom devices. Not ideal, as you can’t pass any additional information.

Also in the future we would like to have the ability to create custom `listenable` events on our devices if possible.

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

test2_device := class(creative_device):

    @editable
    Test1Devices : []test1_device = array{}

    @editable
    TestTrigger : trigger_device = trigger_device{}

    OnBegin<override>()<suspends>:void=
        TestTrigger.TriggeredEvent.Subscribe(OnTriggeredEvent)

    OnTriggeredEvent(Player:agent):void=
        for(X -> Device : Test1Devices):
            Device.TestCall()

```

---

<div class="post-metadata">

**Author:** ![DustinREDGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dustinredgames/32/634988_2.png) [@DustinREDGames](https://forums.unrealengine.com/u/DustinREDGames)\
**Post date:** [March 3, 2023, 4:35pm UTC](https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865/6 "2023-03-03T16:35:06Z")

</div>

This is still not working in 23.50.

---

<div class="post-metadata">

**Author:** ![Hannes\_Uta\_FCT](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hannes_uta_fct/32/702222_2.png) [@Hannes\_Uta\_FCT](https://forums.unrealengine.com/u/Hannes_Uta_FCT)\
**Post date:** [March 7, 2023, 9:22am UTC](https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865/7 "2023-03-07T09:22:43Z")

</div>

> [@Tom.Noonan](#):
>
> `[]`

Confirming this is still an issue, confirming the workaround does work

---

<div class="post-metadata">

**Author:** ![ProfessionalBot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/professionalbot/32/962134_2.png) [@ProfessionalBot](https://forums.unrealengine.com/u/ProfessionalBot)\
**Post date:** [March 7, 2023, 10:37am UTC](https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865/8 "2023-03-07T10:37:54Z")

</div>

Also confirming that this is still an issue, but the workaround works fine for me.

---

<div class="post-metadata">

**Author:** ![DustinREDGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dustinredgames/32/634988_2.png) [@DustinREDGames](https://forums.unrealengine.com/u/DustinREDGames)\
**Post date:** [March 14, 2023, 9:51pm UTC](https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865/9 "2023-03-14T21:51:53Z")

</div>

Custom device to custom device method calls without resetting locally scoped properties is now working in v24.0

---

<div class="post-metadata">

**Author:** ![DustinREDGames](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dustinredgames/32/634988_2.png) [@DustinREDGames](https://forums.unrealengine.com/u/DustinREDGames)\
**Post date:** [March 20, 2023, 4:07pm UTC](https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865/10 "2023-03-20T16:07:27Z")

</div>

This appears to still be an issue in 24.01, along with more issues.

Here is a test project with two test devices that reference each other and call a method from one device to another.  
[Test11.zip](https://forums.unrealengine.com/uploads/short-url/zDjVvUbvCLBIJigRs8KTVNQS1KO.zip) (279.8 KB)

Super strange, when I set the device reference in the array on test2\_device, then push changes up, the device is removed from my level?!

No properties set on either device:

 ![Screenshot (65)](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/0/2/b0272a8e732955310b1e4a792795c71006079272.jpeg)

Set properties on devices and test2\_device disappears:

 ![Screenshot (66)](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/b/1/eb1dbd3b4c5c9f70e742330f389ef6849651a5fb.jpeg)

Zero Verse errors, zero Asset Check fails.

test1\_device:  
 ![Screenshot (67)](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/3/0/a30249c104de4c3e9dc9931779f6473fd8779981.png)

test2\_device:  
 ![Screenshot (68)](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/3/2/c324aeae4f2667e12202afb81a495b15a1362b80.png)

---

<div class="post-metadata">

**Author:** ![Tom.Noonan](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tom.Noonan](https://forums.unrealengine.com/u/Tom.Noonan)\
**Post date:** [March 22, 2023, 9:24pm UTC](https://forums.unrealengine.com/t/blocker-custom-devices-local-variables-are-reset-when-called-from-another-device/766865/11 "2023-03-22T21:24:49Z")

</div>

There was an issue with circular references between devices which like you said, leads to one of the devices disappearing. This should be fixed in a later release.

Individual non-circular references from one custom device to another _should_ still work fine in the mean time.
