# Actor's Uproperty contains null pointer after begin BeginPlay

**URL:** <https://forums.unrealengine.com/t/actors-uproperty-contains-null-pointer-after-begin-beginplay/238353>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [July 1, 2021, 5:06am UTC](https://forums.unrealengine.com/t/actors-uproperty-contains-null-pointer-after-begin-beginplay/238353 "2021-07-01T05:06:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![LXFrontier](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LXFrontier](https://forums.unrealengine.com/u/LXFrontier)\
**Post date:** [July 1, 2021, 7:53am UTC](https://forums.unrealengine.com/t/actors-uproperty-contains-null-pointer-after-begin-beginplay/238353/2 "2021-07-01T07:53:40Z")

</div>

You shouldn’t create objects in your constructor. Try using BeginPlay() or PostInitializeComponents().

> **[Actor Lifecycle](https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/ProgrammingWithCPP/UnrealArchitecture/Actors/ActorLifecycle/)**
>
> What actually happens when an Actor is loaded or spawned, and eventually dies.

What happens during object construction in UE4 is a whole mystical process to me, and there are tons of threads of people trying to understand it. If you want, I suggest you look into Unreal’s reflection system, how CDOs work, and look into threads trying to demystify the whole process.  
Or just use BeginPlay() and leave it for another day.

AActor::OnConstruction() is the native version of the construct script in blueprints, but this case doesn’t seem to want that.

I kept this bookmarked since I was confused by this when I was starting out as well:

> [@UPROPERTY member vars reset to NULL by ObjectInitializer](https://forums.unrealengine.com/t/uproperty-member-vars-reset-to-null-by-objectinitializer/19959/11):
>
> The biggest thing that stands out is this: //StatsComponent.cpp UStatsComponent::UStatsComponent(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { Stats = \*\*NewObject\<URPGStats\>(this)\*\*; check(Stats); //always valid } Objects constructed in this fashion will not have the proper flags set that mark it as a subobject for serialization. I suspect what is happening here is that the constructor is invoked, then in ~FObjectInitializer, property values are serialized…

UObjects shouldn’t have a specifier of the “Edit” variety either. You should be using VisibleDefaultsOnly.

> **[Property Specifiers](https://docs.unrealengine.com/4.26/en-US/ProgrammingAndScripting/GameplayArchitecture/Properties/Specifiers/)**
>
> Keywords used when declaring UProperties to specify how the property behaves with various aspects of the Engine and Editor.

This video goes through it nicely too.

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/7/e/47e2d05ce3497f6dc4c022de8756d1941c865549.jpeg "Unreal Engine 4 - UPROPERTY Explained [Breakdown Series]") ](https://www.youtube.com/watch?v=ZPJtFa9srXw)

---

_[View the full topic](https://forums.unrealengine.com/t/actors-uproperty-contains-null-pointer-after-begin-beginplay/238353)._
