How to initialize an actor property with a field of a DataAsset instance

I am trying to initialize an actors property with a field of a DataAsset. The structure is rougly like so:

 // in ASomeActor
 // [...]
 USomeDataAssset* DataAsset;
 
 private:
     FSomeStruct Data;
 // [...]
 
 // in USomeDataAsset
 // [...]
 UPROPERTY(...)
 FSomeStruct Data;
 // [...]

Now, I’d like to do the following: If, in ASomeActor, DataAsset is not a nullptr, set Data = DataAsset->Data.

Is it possible to do this during construction of the actor? It doesn’t seem to work if done in the actors constructor function, though it also doesn’t produce an error, either in play or during compilation. I assume this is because defaults are initialized after the constructor.

I’ve come across AActor::PostInitProperties(), which looks rather fit for the purpose, during some initial research, but naïve me just crashed the editor when trying to mindlessly override that function, so that might require some additional thought ;_;

What I’d like to achieve with all this is that the Data property of ASomeActor has the FSomeStruct’s defaults when DataAsset is a nullptr, and otherwise takes on the value of the FSomeStruct of the USomeDataAsset instance.

Should this be done in a construction script, or the c++ equivalent thereof?

Any advice is greatly appreciated!

EDIT: After some research I came across this piece of information, which showed me that OnConstruction was the place to do my silly business.

I did not! Thanks for the info, I figured something along those lines might’ve been the problem. In the meantime, I discovered that OnConstruction() was a better fit for my use case tho.

Did you put Super::PostInitProperties() when you overrided that function? if you don’t put call on super on override you are effectively blocking portion of engine code that may cause crashes

Ok then i convert to anwser :slight_smile: