# Is it possible to replicate subobject inside of another subobject?

**URL:** <https://forums.unrealengine.com/t/is-it-possible-to-replicate-subobject-inside-of-another-subobject/430077>\
**Category:** C++\
**Tags:** unreal-engine, UE4, CPP, question\
**Created:** [July 23, 2018, 5:05pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-replicate-subobject-inside-of-another-subobject/430077 "2018-07-23T17:05:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NickTQ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NickTQ](https://forums.unrealengine.com/u/NickTQ)\
**Post date:** [July 23, 2018, 5:05pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-replicate-subobject-inside-of-another-subobject/430077/1 "2018-07-23T17:05:48Z")

</div>

As stated in the Replication article:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

We can replicate subobjects inside of Actors.

Is it possible to make a replicated subobject property inside of the another replicated subobject (which belongs to Actor)?

P.S: Both subobjects are created with NewObject()

---

<div class="post-metadata">

**Author:** ![NickTQ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NickTQ](https://forums.unrealengine.com/u/NickTQ)\
**Post date:** [July 28, 2018, 8:07am UTC](https://forums.unrealengine.com/t/is-it-possible-to-replicate-subobject-inside-of-another-subobject/430077/2 "2018-07-28T08:07:29Z")

</div>

Okay, seems it’s probably abandoned place. Just like BeyondUnreal forums =/

But anyway if anyone can find it with google search here is the answer:

Yes, it’s possible, it’s very similar to described method from Epic’s article ([A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums](https://wiki.unrealengine.com/Replication#Advanced:_Generic_replication_of_Actor_Subobjects))

Here is the code:

* * *

**Child subobject header code:**

```
public:

	// Subobject replication
	virtual bool IsSupportedForNetworking() const override { return true; }

```

* * *

**The parent subobject cpp:**

```
UErrandGoal* NewGoal = NewObject<UErrandGoal>(GetOuter(), GoalClass);

```

Pay attention to this code, you should use the actor Outer (parent’s outer) for your child subobject.

```
void UDayInfo::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);

	DOREPLIFETIME(UDayInfo, ErrandInstances);
}

```

Make your child subobjects replicated as usual

* * *

**The parent subobject header:**

```
	UPROPERTY(Replicated, Instanced)
	TArray<UErrandInfo*> ErrandInstances;

```

* * *

**And finally your Actor cpp:**

```
bool AP2GameState::ReplicateSubobjects(class UActorChannel *Channel, class FOutBunch *Bunch, FReplicationFlags *RepFlags)
{
	bool bSuper = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);

	for( auto CheckDay : DayInstances ) // here DayInstances are parent subobjects
	{
		if( CheckDay != nullptr )
		{
			if( Channel->ReplicateSubobject(CheckDay, *Bunch, *RepFlags) )
			{
				return true;
			}
			else for( auto CheckErrand : CheckDay->ErrandInstances ) // here ErrandInstances are child subobjects
			{
				if( CheckErrand != nullptr && Channel->ReplicateSubobject(CheckErrand, *Bunch, *RepFlags) )
				{
					return true;
				}
			}
		}
	}

	return bSuper;
}

```

* * *
