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

**URL:** <https://forums.unrealengine.com/t/how-to-initialize-an-actor-property-with-a-field-of-a-dataasset-instance/478692>\
**Category:** C++\
**Tags:** actor, initialization, unreal-engine, question, CPP\
**Created:** [February 13, 2021, 8:11pm UTC](https://forums.unrealengine.com/t/how-to-initialize-an-actor-property-with-a-field-of-a-dataasset-instance/478692 "2021-02-13T20:11:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_23884ee2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_23884ee2](https://forums.unrealengine.com/u/anonymous_user_23884ee2)\
**Post date:** [February 13, 2021, 8:11pm UTC](https://forums.unrealengine.com/t/how-to-initialize-an-actor-property-with-a-field-of-a-dataasset-instance/478692/1 "2021-02-13T20:11:02Z")

</div>

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](https://docs.unrealengine.com/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Actors/ActorLifecycle/index.html) piece of information, which showed me that `OnConstruction` was the place to do my silly business.

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [February 13, 2021, 8:12pm UTC](https://forums.unrealengine.com/t/how-to-initialize-an-actor-property-with-a-field-of-a-dataasset-instance/478692/2 "2021-02-13T20:12:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_23884ee2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_23884ee2](https://forums.unrealengine.com/u/anonymous_user_23884ee2)\
**Post date:** [February 13, 2021, 8:15pm UTC](https://forums.unrealengine.com/t/how-to-initialize-an-actor-property-with-a-field-of-a-dataasset-instance/478692/3 "2021-02-13T20:15:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [February 14, 2021, 1:28pm UTC](https://forums.unrealengine.com/t/how-to-initialize-an-actor-property-with-a-field-of-a-dataasset-instance/478692/4 "2021-02-14T13:28:33Z")

</div>

Ok then i convert to anwser 🙂
