I keep getting this error whenever I follow the Persistence Documentation, although I did not get any errors until after the most recent update had come out, any fixes?
All field initializers must come before constructor calls in archetype instantiation.
It looks like the latest UEFN update introduced a stricter rule for how you can create new objects in Verse. I ran into the same thing, and the error message tells you exactly how to fix it: “All field initializers must come before constructor calls in archetype instantiation.”
This means you simply need to change the order of the lines inside your object instantiation block.
The Fix
The old way allowed you to call a copy constructor and then override a field. The new, correct way requires you to set your new field values first, and then call the copy constructor to fill in the rest.
Old Way (Now causes an error):
NewData := my_data_class
{
# This order is now invalid.
MakeMyDataClass<constructor>(ExistingData)
MyFieldToChange := NewValue
}
New Way (Corrected):
NewData := my_data_class
{
# Correct order: Set specific fields first, then call the constructor.
MyFieldToChange := NewValue
MakeMyDataClass<constructor>(ExistingData)
}
Essentially, you’re now telling the compiler: “I’m creating a new object. First, use this specific NewValue for MyFieldToChange. For all the other fields that I didn’t specify, copy them from ExistingData.”
You’ll need to go through your code and swap the lines in any place you’re using this pattern. It’s a quick fix once you know what to look for!