Replicating a cpp type on blueprint

Hi,

I created in c++ a new type for use in blueprints. The type works and it behaves correctly.
Hovever, when I set on the blueprint that variable as replicated, it is not.
I have tested and if I create a variable of a different type with the same setup, it is replicated, so I assume is something wrong with my type definition.

In terms of the class definition (EDITED)

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Object.h"
#include "Order.h"
#include "UnrealNetwork.h"
#include  "MasterGruntC.h"
#include "Plan.generated.h"


/**
*
*/
UCLASS(BlueprintType, Blueprintable)
class THESIS_API UPlan : public  UObject
{
	GENERATED_BODY()
public:

	UPROPERTY(Replicated)
	bool bcanContinue;
	UPROPERTY(Replicated)
	TArray < UOrder*> orders;
	UPROPERTY(Replicated)
	TArray < AMasterGruntC*> soldiers;
	UPROPERTY(Replicated)
	FString planName;
	UPROPERTY(Replicated)
	int planPhase;


	
	UPlan(FString newPlanName);
	UPlan();

	//Plan Maintenance
	UFUNCTION(BlueprintCallable, Category = "Plan")
	void changeName(FString newName);

	UFUNCTION(BlueprintCallable, Category = "Plan")
	void resetPlan();

	//Orders
	UFUNCTION(BlueprintCallable, Category = "Plan")
	bool executeNextOrder();
	UFUNCTION(BlueprintCallable, Category = "Plan")
	void addOrder(UOrder* newOrder);
	UFUNCTION(BlueprintCallable, Category = "Plan")
	FText showOrders();
	UFUNCTION(BlueprintCallable, Category = "Plan")
	void removeOrder(int index);
	
	//Soldiers
	UFUNCTION(BlueprintCallable, Category = "Plan")
	void addNewSoldier(AMasterGruntC* newSoldier);
	UFUNCTION(BlueprintCallable, Category = "Plan")
	void removeSoldier(int index);
	UFUNCTION(BlueprintCallable, Category = "Plan")
	void listSoldiers();
	UFUNCTION(BlueprintCallable, Category = "Plan")
	bool checkIfSoldiersReady();


	//Replication
	void GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const;

};

And the override

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

	DOREPLIFETIME(UPlan, bcanContinue);
	DOREPLIFETIME(UPlan, orders);
	DOREPLIFETIME(UPlan, soldiers);
	DOREPLIFETIME(UPlan, planName);
	DOREPLIFETIME(UPlan, planPhase);

}

And the blueprint setup, where repTest is changed but plan is not.

Finally the var definition on blueprint:

Variables:

126621-notreplicated.png

I changed the c++ parent class from UObject to AInfo, as I read that it had replication already implemented. Still no change.

This is a good start point for learning the concepts of replication in C++: https://wiki.unrealengine.com/Networking/Replication

https://wiki.unrealengine.com/Replication

In short:

  • Declare the members you wish to replicate as UPROPERTY

  • They must be marked UPROPERTY(Replicated)

  • You must override the function

    virtual void GetLifetimeReplicatedProps(class TArray<class FLifetimeProperty, class FDefaultAllocator>& OutLifetimeProps) const;

Thank you for your answer but it still does not work. Edited code in main question.

Please derive your UPlan from AActor, not UObject (and name it APlan), because property replication only works on actors (and members/components of actors) out of the box. Sorry, I thought you had already done this, because you mentioned AInfo in your comment above.

My problem with doing that is the spawn transform needed when creating the plan reference. This class does not need to spawn in the level.

I’m pretty sure you can also get your UObject replicating (I don’t know which implementations are necessary to do that), but I am also pretty sure it will be much easier using an Actor, even if it is not visible in the game. You can use default/empty transform for the spawn.
Another approach would be to make the Plan a UActorComponent of another Actor in your game. Not sure if this fits better into your design.
It is also possible to let the Plan be a component of your GameMode or GameState class (which are both actors, even though they do not spawn in level, btw).