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. 

GetLifetimeReplicatedProps calls only once on subobject

I used the subobject replication on Character child class. The replication code in subobject:

 void UIndicatorsComponent::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
     DOREPLIFETIME(UIndicatorsComponent, Health);

But this code runs only once. Consequently Health property is not replicated when it changes.

Code in class that replicates this subobject:

 bool ASADCharacter::ReplicateSubobjects(class UActorChannel *Channel, class FOutBunch *Bunch, FReplicationFlags *RepFlags)
     bool WroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags);
     if (Indicators != nullptr)
         WroteSomething |= Channel->ReplicateSubobject(Indicators, *Bunch, *RepFlags);
     return WroteSomething;

Subobject has this :

 float Health;

 virtual bool IsSupportedForNetworking() const override
     return true;

Product Version: UE 4.10
more ▼

asked Jan 16 '16 at 08:31 AM in C++ Programming

avatar image

564 44 64 92

avatar image cancel Jan 16 '16 at 08:41 AM

That's not a bug. You are misunderstanding how it works.

Unreal will automatically replicate any UPROPERTY declared properties by declaring that they are Replicated and implementing UObject::GetLifetimeReplicatedProps(). Warning: It is vitally important that you do not conditionally replicate values inside GetLifetimeReplicatedProps (i.e. do not use any of your objects instance state to conditionally wrap DOREPLIFETIME). Doing this will not do what you think (internally Unreal only ever calls GetLifetimeReplicatedProps() on the first instance of an object of a given class and it expects to be given the replication layout for that class, not for an instance of that class. That replication layout is shared by all instances of that class for the lifetime of the UNetDriver).

You can read more here:


Whatever problem you are having is caused by something else. Most likely, your subobject is not replicated its own properties correctly. If you post the code, I can take a look at it.

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

1 answer: sort voted first

You're attempting to manually replicate a subclass of UActorComponent. It will misbehave. You have two choices:

A. Derive from UObject for your subobject and replicate manually (implementing IsSupportedForNetworking on the subobject, implementing ReplicateSubobjects on the Actor, etc. as you've mostly done, but see notes below)

B. Derive from UActorComponent for your subobject. Then simply set it as bReplicates, and make sure you've registered the component (which adds it to the Components list for your Actor). UE4 will handle all other stuff for replication.

Note: for replication for work properly on your UObject-derive subobject, you also need to implement GetWorld, GetFunctionCallspace, and CallRemoteFunction.

There are also a couple of other mistakes in your code. You've implemented ReplicateSubobjects on your UIndicatorsComponent, but assuming you were replicating it manually, it would never be called. Your outer ASADCharacter must call it from within its own ReplicateSubobjects.

One more additional note: if you're able to create your UIndicatorsComponent using CreateDefaultSubobject in your initializer, that would be good. Then your component will have a stable name relative to its outer, which means the server and client will have to exchange less data (the client will not have to receive instructions to create the subobject from the server). If the subobject is removed, the server will still correctly tell the client to remove it.

more ▼

answered Jan 16 '16 at 10:38 AM

avatar image

2.4k 101 72 123

avatar image broly Jan 16 '16 at 11:29 AM

Okay! Thanks a lot!

(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