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.