# Instantiating a struct in Verse

**URL:** <https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [March 25, 2023, 1:13pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142 "2023-03-25T13:13:08Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdooodi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@abdooodi](https://forums.unrealengine.com/u/abdooodi)\
**Post date:** [March 25, 2023, 1:13pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/1 "2023-03-25T13:13:08Z")

</div>

I’m trying to make a struct array, but the one thing that I cannot get to work is the instantiating the struct. I’ve looked at the struct documentation and I’ve just copied and pasted what they had about instantiating it but it still gives off an error (Data definitions at file scope must specify their value domain.) and (This archetype instantiation constructs a class that has the ‘transacts’ effect, which is not allowed by its context.)

below is what I have up to the struct instantiation.

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

# A Verse-authored creative device that can be placed in a level

@editable  
Coordinates := struct {  
X : float = 0.0  
Y : float = 0.0  
}  
Position := Coordinates{X:= 1.0, Y:= 1.0}

---

<div class="post-metadata">

**Author:** ![Cray\_Opeta](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/cray_opeta/32/637656_2.png) [@Cray\_Opeta](https://forums.unrealengine.com/u/Cray_Opeta)\
**Post date:** [March 25, 2023, 1:51pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/2 "2023-03-25T13:51:57Z")

</div>

> [@abdooodi](#):
>
> I’m trying to make a struct array, but the one thing that I cannot get to work is the instantiating the struct. I’ve looked at the struct documentation and I’ve just copied and pasted what they had about instantiating it but it still gives off an error (Data definitions at file scope must specify their value domain.) and (This archetype instantiation constructs a class that has the ‘transacts’ effect, which is not allowed by its context.)
> 
> below is what I have up to the struct instantiation.

No problem like this

```auto
Coordinates := struct:
    X : float = 0.0
    Y : float = 0.0

hello_world_device := class(creative_device):
    Test : Coordinates = Coordinates {
        X:= 0.0,
        Y:= 10.0
    }

```

---

<div class="post-metadata">

**Author:** ![abdooodi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@abdooodi](https://forums.unrealengine.com/u/abdooodi)\
**Post date:** [March 25, 2023, 6:33pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/3 "2023-03-25T18:33:59Z")

</div>

Well I longer get that previous error, but now I get an error that pops up when trying to build it:  
Unhandled attribute type

I can confirm that the struct causes it as when I remove that code the error is no longer there.

---

<div class="post-metadata">

**Author:** ![Yolziii](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/yolziii/32/638353_2.png) [@Yolziii](https://forums.unrealengine.com/u/Yolziii)\
**Post date:** [March 25, 2023, 7:24pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/4 "2023-03-25T19:24:40Z")

</div>

Could you show us the full code? It’s possible that this struct affects other parts of your code in some way. Cray\_Opeta’s code worked fine for me, so seeing the context might help identify an issue.

---

<div class="post-metadata">

**Author:** ![abdooodi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@abdooodi](https://forums.unrealengine.com/u/abdooodi)\
**Post date:** [March 25, 2023, 7:30pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/5 "2023-03-25T19:30:22Z")

</div>

```auto

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

# A Verse-authored creative device that can be placed in a level

@editable
Coordinates := struct {
    X : float = 0.0
    Y : float = 0.0
}

PickMap := class(creative_device):

    Position : Coordinates = Coordinates {
        X:=1.0,
        Y:=3.0
    }
    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        Print("Game Started")

```

---

<div class="post-metadata">

**Author:** ![Yolziii](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/yolziii/32/638353_2.png) [@Yolziii](https://forums.unrealengine.com/u/Yolziii)\
**Post date:** [March 25, 2023, 7:40pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/6 "2023-03-25T19:40:07Z")

</div>

It works if you remove @editable. Is there any reason to use it?

---

<div class="post-metadata">

**Author:** ![abdooodi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@abdooodi](https://forums.unrealengine.com/u/abdooodi)\
**Post date:** [March 25, 2023, 7:44pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/7 "2023-03-25T19:44:18Z")

</div>

Well my plan was to have a struct of teleporter device array (for random tp locations) and have a variable array of that struct to make it easier to create new levels/maps

---

<div class="post-metadata">

**Author:** ![Yolziii](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/yolziii/32/638353_2.png) [@Yolziii](https://forums.unrealengine.com/u/Yolziii)\
**Post date:** [March 25, 2023, 7:53pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/8 "2023-03-25T19:53:54Z")

</div>

You mean something like this?

```auto
Coordinates := struct {
    X : float = 0.0
    Y : float = 0.0
}

PickMap := class(creative_device):

    var Positions : []Coordinates = array{
        Coordinates { X:=1.0, Y:=3.0 } 
    }
    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        Print("Game Started")

    AddPosition(coordinates: Coordinates)<decides> : void =
        set Positions = Positions + array{coordinates}

```

---

<div class="post-metadata">

**Author:** ![abdooodi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@abdooodi](https://forums.unrealengine.com/u/abdooodi)\
**Post date:** [March 25, 2023, 8:08pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/9 "2023-03-25T20:08:09Z")

</div>

Not entirely, I meant as in I could add the values through the editor.  
Similar to this (except this doesn’t have the struct array):

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/9/1/391d5d64b0046537cb0ea0a092f3798ee694c267.png)

I want to use the struct array as a way to organize each map with their own set of teleporters, and to easily implement the actual teleporting.

---

<div class="post-metadata">

**Author:** ![Yolziii](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/yolziii/32/638353_2.png) [@Yolziii](https://forums.unrealengine.com/u/Yolziii)\
**Post date:** [March 25, 2023, 8:24pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/10 "2023-03-25T20:24:41Z")

</div>

If I understood right, @editable is using to mark editable properties of device class, not their types:

> **[Customize Device Properties](https://dev.epicgames.com/documentation/en-us/uefn/customize-device-properties-in-verse)**
>
> Learn how to expose device properties from your Verse-authored device and modify them in Unreal Editor for Fortnite.

---

<div class="post-metadata">

**Author:** ![abdooodi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@abdooodi](https://forums.unrealengine.com/u/abdooodi)\
**Post date:** [March 25, 2023, 8:30pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/11 "2023-03-25T20:30:18Z")

</div>

Yup which is why I had the @editable in the code from before but it gave off that build error about the unhandled attribute type. Any ideas?

```auto
Levels := struct {
    @editable
    Teleporters : []teleporter_device = array{teleporter_device{}}
}

PickMap := class(creative_device):

    Level : []Levels = array{Levels {
    }}

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        Print("Game Started")

```

Putting @editable above ‘Level’ gives an error (The editable attribute is not supported for classes that aren’t concrete.)  
and having it inside the struct doesn’t seem to be doing anything

---

<div class="post-metadata">

**Author:** ![Yolziii](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/yolziii/32/638353_2.png) [@Yolziii](https://forums.unrealengine.com/u/Yolziii)\
**Post date:** [March 25, 2023, 8:37pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/12 "2023-03-25T20:37:49Z")

</div>

> [@abdooodi](#):
>
> p which is why I had the @editable in the code from before but it gave off that build

This works fine for me:

```auto
Coordinates := struct<concrete> {
    @editable
    X : float = 0.0

    @editable
    Y : float = 0.0
}

hello_world_device := class(creative_device):

    @editable
    Positions: []Coordinates = array{}

```

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/a/9/5a99e2f58102cc3db9c6ecbec7f255a905d6ddce.png)

---

<div class="post-metadata">

**Author:** ![abdooodi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@abdooodi](https://forums.unrealengine.com/u/abdooodi)\
**Post date:** [March 25, 2023, 8:40pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/13 "2023-03-25T20:40:23Z")

</div>

Ah now it works, I just needed . Thanks a lot.

---

<div class="post-metadata">

**Author:** ![Resykz](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/resykz/32/677389_2.png) [@Resykz](https://forums.unrealengine.com/u/Resykz)\
**Post date:** [April 10, 2023, 12:39pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/14 "2023-04-10T12:39:10Z")

</div>

Is it possible to get this to work with a device as one of the editable props? Like so:

```auto
capture_item_spawner := struct<concrete> {
    @editable
    Device: capture_item_spawner_device = capture_item_spawner_device {}

    @editable
    Level: int = 0
}

my_game_device := class (creative_device) {
    @editable
    CaptureItemSpawners: []capture_item_spawner = array {}
}

```

Cause right now I can’t seem to get this working, it shows that there are 2 members to each editable item in the array but it’s only showing `Level`:

![editable](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/7/7/b771ee6dacfee1c6da11c6db77f05e95f3ce7c41.png)

I wasn’t sure if its not possible yet, or if it should be and it’s broken or I’ve just set it up wrong.

---

<div class="post-metadata">

**Author:** ![Incredulous\_Hulk](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/incredulous_hulk/32/924210_2.png) [@Incredulous\_Hulk](https://forums.unrealengine.com/u/Incredulous_Hulk)\
**Post date:** [April 10, 2023, 5:49pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/15 "2023-04-10T17:49:48Z")

</div>

Hi @Resykz,

It looks like there is a bug in Verse when referencing creative devices inside structs. This is being worked on and will be fixed in an upcoming release.

---

<div class="post-metadata">

**Author:** ![Resykz](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/resykz/32/677389_2.png) [@Resykz](https://forums.unrealengine.com/u/Resykz)\
**Post date:** [April 10, 2023, 6:06pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/16 "2023-04-10T18:06:19Z")

</div>

Good to know, thanks for the update!

---

<div class="post-metadata">

**Author:** ![Sabasaa1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sabasaa1](https://forums.unrealengine.com/u/Sabasaa1)\
**Post date:** [July 14, 2023, 6:44pm UTC](https://forums.unrealengine.com/t/instantiating-a-struct-in-verse/821142/17 "2023-07-14T18:44:44Z")

</div>

I was having a similar problem where I couldn’t assign the device to a device property in an array of structs, I got this warning “Illegal TEXT reference to a private object in external package”. I changed the struct to be a class and it worked fine 👍
