x

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"

Subobject Replication for Blueprint Child Class

I can setup any UObject I want to replicate in C++ and it does it well with all properties and even sub-sub objects can replicate. However if I create a new Blueprint Object from that same UObject that replicates so well in code and give it new properties that also need to replicate, than those new properties do not replicate at all. I can add a RepNotify to them and the rep notify only gets called on the server. The Subobject exists on both the server and the client, and all the properties that are setup to replicate in C++ replicate just fine, but none of the added blueprint properties do.

My current setup for this is to override the IsSupportedForNetworking() function Second Step AActors, UActorComponents override the ReplicateSubobjects function This replicates the subobjects one at a time or using a for loop if they are in an array.

 /**
 * Setup Property replication
 */
 void USubObjectComponent::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
 {
         Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME(USubObjectComponent, subObjects);
 }
 
 /**
 * Allows Subobject replication on a UObject, must be explicitly called from owning object.
 * param Channel
 * param Bunch
 * param RepFlags  */
   bool USubObjectComponent::ReplicateSubobjects(class UActorChannel *Channel, class FOutBunch *Bunch, FReplicationFlags *RepFlags)
 {
     bool wroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags); for (UMySubObject * subObject: this->subObjects)
     {
         if (subObject!= nullptr && !subObject->IsPendingKill())
         {
             wroteSomething |= Channel->ReplicateSubobject(subObject, *Bunch, *RepFlags);  
             // sub-sub object replication, it works!
             wroteSomething |= subObject->ReplicateSubobjects(Channel, Bunch, RepFlags);
         }
      }
     return wroteSomething;
 }
Product Version: UE 4.18
Tags:
more ▼

asked Feb 09 '18 at 05:43 AM in C++ Programming

avatar image

ArcainOne
454 32 25 55

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

1 answer: sort voted first

alt text

12345.png (21.9 kB)
more ▼

answered Jun 26 '18 at 06:30 AM

avatar image

pittwang
31 2 1

avatar image ArcainOne Jul 13 '18 at 04:52 AM

Holy cow you just saved my framework! Thanks for reposting that!

avatar image ArcainOne Jul 13 '18 at 05:15 AM

So to elaborate on the solution, if you have a Replicated UObject you have created and need Blueprint Variables to also replicate add this to the root class of your replicated UObject's GetLifetimeReplicatedPropers:

  UBlueprintGeneratedClass * bpClass = Cast<UBlueprintGeneratedClass>(this->GetClass());
  if (bpClass != nullptr)
  {
      bpClass->GetLifetimeBlueprintReplicationList(OutLifetimeProps);
  }

avatar image Tom Looman Sep 06 '18 at 12:02 PM

Great Find! Thanks for posting the source.

(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