# How to \<constructor\>?

**URL:** <https://forums.unrealengine.com/t/how-to-constructor/1892024>\
**Category:** Programming & Scripting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [June 6, 2024, 8:18am UTC](https://forums.unrealengine.com/t/how-to-constructor/1892024 "2024-06-06T08:18:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LionUnchained](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lionunchained/32/1039015_2.png) [@LionUnchained](https://forums.unrealengine.com/u/LionUnchained)\
**Post date:** [June 6, 2024, 8:18am UTC](https://forums.unrealengine.com/t/how-to-constructor/1892024/1 "2024-06-06T08:18:24Z")

</div>

I have a few questions about how constructors are intended to work as I’ve been having a lot of difficulty finding a way to use them that’s of any practical use. To preface the reason I’m asking these questions is because my constructors keep crashing verse.

I’ll be referencing this documentation page:  
[https://dev.epicgames.com/documentation/en-us/uefn/constructor-in-verse](https://Constructor)

The first block about defining a constructor I’m clear on.

```auto
MakeClass1<constructor>(Args:int):=class1:
   Val:=Args
class1:=class:
   Val:int

```

Where the breakdown in my understanding occurs is when we get into the following:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/c/d/fcd6c50a255af129c8647e46d437ef3ec296f445.png)

[https://dev.epicgames.com/documentation/en-us/uefn/expressions-in-verse](https://Expressions)

Expressions defines just about everything -

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/3/0/23033d0f3fa9000f7c946addf443b1d05990b9c0.png)  
you can do in the language, so am I to assume that in a let block I can do any type of calculation, with or without failable context, which may or may not complete, etc. or are there some sort of expected restrictions or limitations here?

For example if I’m wanting to use conditionals to decide whether or not to override a value in a constructor can I do this?

```auto
class1<abstract>:=class:
   Value:?int
class2:=class(class1):
   Value<override>:?int
MakeClass2<constructor>(Arg:float):=class2:
   let:
       T_Value:?int=ReturnConditionalValue(Arg)
   Value:=T_Value

```

If I should be able to infer this from the documentation some how please feel free to point that out. Just looking for solutions here. Generally I feel that the documentation here is too vague.

The other scenario would be related to this example block:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/3/b/53bcd8cdefa383c344a57fa52815d6e869230ad6.png)

There is no explicit definition of these classes in the example and no indicator that they are extension or share inheritance in any way. The description states calling _other_ constructors, and then in a separate sentence adds that you can _also_ call constructors for the superclass. I would infer from the information above that I can construct any other class inside a constructor, but when I’ve tried to do that verse has always crashed.

Essentially what I would think I could do inside a constructor is use conditionals to retrieve values and then write those values to fields of the class that I’m constructing, but that doesn’t seem to be the intention. So I’m just curious if there are additional caveats that aren’t stated here or where the breakdown is in communication because I’m not sure how to get much use out of constructors at this point.

If this stuff should work I can go grab some code examples to review and see where I’m going wrong, but I’ll see if there are any responses to this first. (A good example off the top of my head is constructing a custom\_ui class for a custom\_agent, where custom\_ui is a field of custom\_agent, from inside the custom\_agent constructor by calling a custom\_ui constructor.)

---

<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:** [June 7, 2024, 2:34am UTC](https://forums.unrealengine.com/t/how-to-constructor/1892024/2 "2024-06-07T02:34:04Z")

</div>

I can’t find it right now, but we were on a thread talking about much of what you are asking. My take on things is that there are still things yet to be fully implemented and that constructors are a work in progress. I found this thread helpful:

> [@What's the point of Verse constructors?](https://forums.unrealengine.com/t/whats-the-point-of-verse-constructors/1384647):
>
> Design of Verse constructors is a bit weird. Coming from C# if they would be similar we could use them as: MyClass := my\_class(DataForConstructor:my\_data): MyClassVar := OtherVar This makes them very easy to use and discover. After typing my\_class( we get a suggestion list of all possible constructors. Additionally it’s possible to make default constructor private and inaccessible, forcing us to use custom constructor. Verse constructors seem to not differ much from functions? Other then …

---

<div class="post-metadata">

**Author:** ![t.tutiya](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/t.tutiya/32/924637_2.png) [@t.tutiya](https://forums.unrealengine.com/u/t.tutiya)\
**Post date:** [June 10, 2024, 5:14am UTC](https://forums.unrealengine.com/t/how-to-constructor/1892024/3 "2024-06-10T05:14:48Z")

</div>

Hi.  
for more information.

> [@Question about constructor function](https://forums.unrealengine.com/t/question-about-constructor-function/1761501):
>
> What is the difference between the following two functions? #cat := class: # Name:string # Sound:string MakeCat1\<constructor\>(name:string, sound:string) := cat: Name := name Sound := sound MakeCat2(name:string, sound:string):cat = cat: Name := name Sound := sound If they are the same, wouldn’t the constructor specifier be meaningless?

And, Nest constructors can be useful when creating persistent data.

> **[Using Persistable Data In Verse | Unreal Editor For Fortnite Documentation |...](https://dev.epicgames.com/documentation/en-us/uefn/using-persistable-data-in-verse#usingconstructorsforpartialupdates)**
>
> Create custom save data that persists across game sessions in Verse.

---

<div class="post-metadata">

**Author:** ![LionUnchained](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lionunchained/32/1039015_2.png) [@LionUnchained](https://forums.unrealengine.com/u/LionUnchained)\
**Post date:** [June 10, 2024, 5:56am UTC](https://forums.unrealengine.com/t/how-to-constructor/1892024/4 "2024-06-10T05:56:38Z")

</div>

I am currently writing my persistent data using the same method and found great use of computed module level classes as in their example.

I think that at this point the only true purpose for constructors that I can find are mutating persistent classes (hopefully that’s the right terminology). If there is some use case for them outside of this I haven’t gotten to that skill/knowledge level to use it yet.  
I do use them in part with module level computed classes to consolidate my predefined default class values, then pass them into constructor args, but its just organizational it doesn’t actually add any functionality.

I am not sure what the benefit of “pure” classes are but I could see wanting to reconstruct my abilities with new constant values for upgrades and whatnot. It’s just a bit hard to justify when I can just check for upgrade values at the start of my OnUse function, and write to optional function level values.  
I doubt unwrapping 1 optional tuple to decide logic once per ability use is going to make a difference. Optionals making everything too easy XD
