# Adding to SubObject list in Constructor causing reference exception

**URL:** <https://forums.unrealengine.com/t/adding-to-subobject-list-in-constructor-causing-reference-exception/2409833>\
**Category:** C++\
**Tags:** uobject, Replication, unreal-engine, question\
**Created:** [March 23, 2025, 1:52am UTC](https://forums.unrealengine.com/t/adding-to-subobject-list-in-constructor-causing-reference-exception/2409833 "2025-03-23T01:52:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kotaru\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kotaru\_1](https://forums.unrealengine.com/u/Kotaru_1)\
**Post date:** [March 23, 2025, 1:52am UTC](https://forums.unrealengine.com/t/adding-to-subobject-list-in-constructor-causing-reference-exception/2409833/1 "2025-03-23T01:52:14Z")

</div>

I’m following [this](https://dev.epicgames.com/documentation/en-us/unreal-engine/replicating-uobjects-in-unreal-engine#serverandclientsubobjectlists) guide on SubObject replication, but I ran into this issue that I’m not understanding

The guide says to add the following to the Actor’s constructor

```auto
     if(IsValid(MyActorSubobject))
     {
         RemoveReplicatedSubObject(MyActorSubobject);
     }
 
     MyActorSubobject = NewObject<UMyObject>();
     MyActorSubobject->ReplicatedValue = 1;
 
     // MyActorSubobject becomes a replicated subobject here 
     AddReplicatedSubObject(MyActorSubobject);

```

however it causes a null reference when calling `AddReplicatedSubObject(MyActorSubobject)`

My understanding of this code is that if the SubObject is valid, it removes it from the replicated subobject list before executing the rest

Then it creates an instance of the UMyObject subobject and assigns it to MyActorSubobject,

Finally it adds the newly assigned subobject to the replicated subobject list

How is there room for a null here?

---

<div class="post-metadata">

**Author:** ![Auran131](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Auran131](https://forums.unrealengine.com/u/Auran131)\
**Post date:** [March 23, 2025, 2:58am UTC](https://forums.unrealengine.com/t/adding-to-subobject-list-in-constructor-causing-reference-exception/2409833/2 "2025-03-23T02:58:32Z")

</div>

havent tried it myself but just lower it says

If you want to construct your subobject directly in your actor’s constructor, use `AActor::CreateDefaultSubobject` instead of `AActor::NewObject`. To learn more about object creation in UE, see the [UObject Creation](https://dev.epicgames.com/documentation/en-us/unreal-engine/objects-in-unreal-engine#uobjectcreation) documentation.

i think NewObject could fail on the construction because it may not have a valid world/outer etc?

---

<div class="post-metadata">

**Author:** ![ShadowBr0kerz](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shadowbr0kerz/32/1201558_2.png) [@ShadowBr0kerz](https://forums.unrealengine.com/u/ShadowBr0kerz)\
**Post date:** [October 21, 2026, 1:01pm UTC](https://forums.unrealengine.com/t/adding-to-subobject-list-in-constructor-causing-reference-exception/2409833/3 "2026-10-21T13:01:01Z")

</div>

dont call NewObject plus AddReplicatedSubObject inside the constructor, there is no channel yet so the add call has nothing to attach to. for constructor time use CreateDefaultSubobject, and for runtime objects do the NewObject plus add in BeginPlay or later after the actor has a connection. also remove before you re add if you recreate it.

you can also try Blueprint Object Replication, a replication tool for Unreal Engine that hosts plain objects on an actor component so you never touch the subobject list by hand: [https://www.fab.com/listings/e26dcf07-7c78-4e67-8e56-272cf6df8021](https://www.fab.com/listings/e26dcf07-7c78-4e67-8e56-272cf6df8021)
