Is it possible to replicate subobject inside of another subobject?

As stated in the Replication article:

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()

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)

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;
}