Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Replicating a cpp type on blueprint


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
     bool bcanContinue;
     TArray < UOrder*> orders;
     TArray < AMasterGruntC*> soldiers;
     FString planName;
     int planPhase;
     UPlan(FString newPlanName);
     //Plan Maintenance
     UFUNCTION(BlueprintCallable, Category = "Plan")
     void changeName(FString newName);
     UFUNCTION(BlueprintCallable, Category = "Plan")
     void resetPlan();
     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);
     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();
     void GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const;

And the override

 void UPlan::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const {
     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.

alt text

Finally the var definition on blueprint:

alt text


alt text

Product Version: UE 4.14
repsetup.png (113.8 kB)
repsetup.png (133.0 kB)
varsetup.png (27.2 kB)
more ▼

asked Feb 16 '17 at 01:03 PM in C++ Programming

avatar image

64 8 17 22

avatar image JackcaJ2314 Feb 16 '17 at 02:14 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

This is a good start point for learning the concepts of replication in C++: https://wiki.unrealengine.com/Networking/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& OutLifetimeProps) const;

more ▼

answered Feb 16 '17 at 05:21 PM

avatar image

581 14 12 37

avatar image JackcaJ2314 Feb 16 '17 at 10:35 PM

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

avatar image Wurmloch83 Feb 17 '17 at 06:05 PM

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.

avatar image JackcaJ2314 Feb 17 '17 at 07:10 PM

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.

avatar image Wurmloch83 Feb 17 '17 at 07:20 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question