# Question about constructor function

**URL:** <https://forums.unrealengine.com/t/question-about-constructor-function/1761501>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [March 19, 2024, 3:20am UTC](https://forums.unrealengine.com/t/question-about-constructor-function/1761501 "2024-03-19T03:20:45Z")\
**Posts on this page:** 10\
**Page:** 1

<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:** [March 19, 2024, 3:20am UTC](https://forums.unrealengine.com/t/question-about-constructor-function/1761501/1 "2024-03-19T03:20:45Z")

</div>

What is the difference between the following two functions?

```auto
#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?

---

<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:** [March 19, 2024, 11:26pm UTC](https://forums.unrealengine.com/t/question-about-constructor-function/1761501/2 "2024-03-19T23:26:16Z")

</div>

First off, I think this is a really great question, and one I am looking at right now too.

Within the context of the code you’ve provided, I would say it does not appear to make any difference. And does not generate an error. But within other contexts, it seems to have a major role. Most notably, if you look at the Persistent Stats Tutorial, they make heavy use of constructors, and say that constructors are required because “Verse persistence does not allow classes containing variable fields to be persistable.” In replicating just a small portion of that code, it will not work without a constructor. See pic.

 ![constructor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/4/e/64e468eec9b7deac28dfcf00a3a2cce7d9df31e4.jpeg)

---

<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:** [March 20, 2024, 1:21am UTC](https://forums.unrealengine.com/t/question-about-constructor-function/1761501/3 "2024-03-20T01:21:07Z")

</div>

Thanks for the reply!  
Unfortunately, that code can be given a return type to avoid compile errors

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

---

<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:** [March 20, 2024, 3:14am UTC](https://forums.unrealengine.com/t/question-about-constructor-function/1761501/4 "2024-03-20T03:14:25Z")

</div>

Does this post help you?

> [@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 …

In it, the UltimateLambda concludes with this:  
“If you don’t intend to use a constructor function with other constructor functions, you may be better served with a plain function.”

P.S. I did remove the constructors from the Persistent tutorial example, and it worked with just plain functions as you showed, as long as the return type was manually specified.

---

<div class="post-metadata">

**Author:** ![Kamyker](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kamyker/32/1194621_2.png) [@Kamyker](https://forums.unrealengine.com/u/Kamyker)\
**Post date:** [March 20, 2024, 3:19pm UTC](https://forums.unrealengine.com/t/question-about-constructor-function/1761501/6 "2024-03-20T15:19:59Z")

</div>

> [@ok\_studios](#):
>
> I did remove the constructors from the Persistent tutorial example, and it worked with just plain functions as you showed, as long as the return type was manually specified.

This is kinda wrong, it compiles correctly but doesn’t do deep clone when using normal function as constructor as shown in Persistent tutorial example.

> <https://twitter.com/t_tutiya/status/1770465884144042107>

---

<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:** [March 20, 2024, 10:14pm UTC](https://forums.unrealengine.com/t/question-about-constructor-function/1761501/7 "2024-03-20T22:14:51Z")

</div>

Interesting. Is it safe to say then that constructors would be required in the Persistence example and that a plain function would be insufficient? Thanks!

---

<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:** [March 21, 2024, 2:38am UTC](https://forums.unrealengine.com/t/question-about-constructor-function/1761501/8 "2024-03-21T02:38:44Z")

</div>

> [@ok\_studios](#):
>
> In it, the UltimateLambda concludes with this:  
> “If you don’t intend to use a constructor function with other constructor functions, you may be better served with a plain function.”

I had missed that post. Thanks!

---

<div class="post-metadata">

**Author:** ![Kamyker](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kamyker/32/1194621_2.png) [@Kamyker](https://forums.unrealengine.com/u/Kamyker)\
**Post date:** [March 28, 2024, 9:43pm UTC](https://forums.unrealengine.com/t/question-about-constructor-function/1761501/9 "2024-03-28T21:43:49Z")

</div>

They would be fine but you shouldn’t use them with `<constructors>, was confirmed as a bug in recent Q&A`

---

<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:** [April 17, 2024, 7:18am UTC](https://forums.unrealengine.com/t/question-about-constructor-function/1761501/10 "2024-04-17T07:18:08Z")

</div>

From: Ask Epic : Verse

> [@Ask Epic: Verse - March 28 @ 10:00 AM ET](https://forums.unrealengine.com/t/ask-epic-verse-march-28-10-00-am-et/1765393/104):
>
> That looks like a bug (I’m making a bug report for it currently). It won’t act at all like the version in an archetype instantiation, but instead will just act like a plain function invocation, producing a new instance of cat with Name as "foo" and Sound as "boo".

> That looks like a bug (I’m making a bug report for it currently). It won’t act at all like the version in an archetype instantiation, but instead will just act like a plain function invocation, producing a new instance of `cat` with `Name` as `"foo"` and `Sound` as `"boo"` .

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [May 17, 2024, 7:18am UTC](https://forums.unrealengine.com/t/question-about-constructor-function/1761501/11 "2024-05-17T07:18:18Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
