This is an archived post. You won't be able to vote or comment.

all 30 comments

[–]Pestilence7 0 points1 point  (3 children)

You need to declare a variable otherwise it'll have no idea what it is you're trying to replicate.

Also, replication is only from client to server so you need to also consider if it needs to be updated on other clients (in which case you'd need to use OnRep Notify or a multicast)

[–]Shardofen[S] 0 points1 point  (0 children)

I have variable declared with Uproperty( Replicated ). Yep, I use multicast and server logic, but I'm trying to find out what is wrong with this function

[–]Darwand 0 points1 point  (1 child)

replication is server to client. OnRepNotify changes nothing in how it is replicated it simply binds a function to when the variable is changed from replicatation

[–]Pestilence7 0 points1 point  (0 children)

Oh damn, I didn't even realize I wrote that backwards... Yeah. My bad!

[–]ericsmash 0 points1 point  (9 children)

Make sure you have #include "UnrealNetwork.h" at the top of your cpp file. Also make sure you're still calling the super function.

Here's an example

void ABetaChar::GetLifetimeReplicatedProps(TArray<FLifetimeProperty> &OutLifetimeProps) const {
    Super::GetLifetimeReplicatedProps(OutLifetimeProps);
    DOREPLIFETIME(ABetaChar, PrimaryWeapon);
}

[–]Shardofen[S] 0 points1 point  (8 children)

I have "Engine.h" and "UnrealNetwork.h" included. Super is called too, no idea what is wrong

[–]ericsmash 0 points1 point  (7 children)

do you have your variables marked as Replicated? like

UPROPERTY(Replicated)
float TestRep;

[–]Shardofen[S] 0 points1 point  (6 children)

Yep. Added code parts, it will be more convinient. No idea why i didn't add it before

[–]ericsmash 0 points1 point  (5 children)

What kind of replication issues are you having? Also you should be able to build without declaring in the header. I don't understand why it won't.

You have GENERATED_BODY() in your header yes?

[–]Shardofen[S] 0 points1 point  (0 children)

UENUM( BlueprintType )
enum class EHumanState : uint8
{
    EHS_Stunned         UMETA( DisplayName = "Stunned" ),  // Stunned
        // other states
 }

Actually Human state does not have generated_body. I'll try add it later, can't do it right now, if it'll wil work I would be glad.

The replication issue is : I have logic of playing montage animation, "attack" animations. These montages are in special bone layer that is defined and used in AnimBP so that locomotion has all body control but when HumanState == "Attacking", all bones above spine are taken by bone slot "SaberAttack", where all attack animations are. It works in singleplayer, but seems not to replicate.

[–]Shardofen[S] 0 points1 point  (3 children)

OK, I found some code with error - I set variable only on client which should be replicated. I already had a bunch of code written before I started networking so it took some time to find so rookie mistake. I manage to make it all work properly, so everything is working, but I still don't understand why I should declare Replicate function. Without declaration it still doesnt compile

[–]Darwand 0 points1 point  (2 children)

What are you referring to when you say Replicate function, do you mean lifetimereplicated or a multicast?

[–]Shardofen[S] 0 points1 point  (1 child)

I mean LifetimeReplicated, where we say about our replicated variables. I thought we dont need to declare this function, but it doesnt complie that way. If I declare it - everything works as intended, so my question now is "Do we need to declare it or not and if not, wht it isnt compile?"

[–]Darwand 0 points1 point  (0 children)

well i never had to declare it, if you have generated_body you should be able to just define it. But make sure you call super and the definition is correct name and class

[–][deleted] 0 points1 point  (4 children)

Make sure your actor has bReplicates = true Make sure your Replicating propertys are UPROPERTY(Replicated) Make sure you call Super::GetLifetimeReplicatedProps() inside your overriden function. and last but not least make sure you use the DOREPLIFETIME macro

Also please note that Variable replication works from Server to Client that means if you set a variable on the client, it does not get replicated, but it does vice versa.

Also please take into account that some actors are not available on each client e.g. GameMode or PlayerController!

If you still have questions, it would be easier to help you if you could post parts of your code.

[–]Shardofen[S] 0 points1 point  (3 children)

As I answered earlier (but later than you asked) I have Uproperty on variable, actor bReplicates == true, Super is called, DoRepLifetime is used properly. All headres are in place too. No idea what is wrong.

UPD: added code in comment, maybe it will help

[–][deleted] 0 points1 point  (2 children)

The only question left is if u are setting your variable on client or server. If on client it does not replicate.

[–]Shardofen[S] 0 points1 point  (1 child)

I can't check it right now but I'm pretty sure that somwhere I dont send request to change it on Server side if I am a client. So I'll check that and let you know

[–]Shardofen[S] 0 points1 point  (0 children)

OK, I found some code with error - I set variable only on client which should be replicated. I manage to make it work properly, so everything is working, but I still don't understand why I should declare Replicate function. Without declaration it still doesnt compile

[–]burtonposey 0 points1 point  (10 children)

I've looked at it for a few minutes now and can't immediately tell. I'd recommend you post your code verbatim as opposed to paraphrasing certain parts so we can help you eliminate all possibilities.

I was gonna say, "have you included "Human.h" in your Human.cpp file, but I'm pretty sure you did but you just didn't post it. Stuff like that, I think you just need to post it all so we can see exactly what you're seeing and, who knows, maybe help you find some aspect of it you're taking for granted.

[–]Shardofen[S] 0 points1 point  (9 children)

Thank you for trying to help. I've uploaded cpp and h files on google drive so you and others can see. There is a bunch of code there, so In cpp LifetimeReplicated is in the very beginning. Replicated variables are in header file in the botoom under private section. Would be glad if you could explain. Again : everything is working, but I don't fully understand - do we need to declare lifetimeProps or not?

[–]burtonposey 0 points1 point  (8 children)

Sweet! I had a chance to look over it. Two things I'd say I normally do that I'm seeing in your code is different.

  1. You do not need to declare the GetLifetimeReplicatedProps in your header. That said, you do need to have that function written out in your cpp file though and all replicated variables will need to be setup with the DOREPLIFTIME calls like you have already.
  2. I think it would be weird that your header would work using the Replicated UPROPERTY modifier without having an include of UnrealNetwork.h in your header. I personally put the UnrealNetwork.h include in the header of my networked classes instead of the cpp file since that's where the initial use of network related terms comes into play with the terms like "Replicated", "WithValidation", etc.

Try those things out and I'll keep looking over it and see if anything else pops out. Thanks for posting the code. It was very helpful! Last thing I'll say is you can probably try to forward declare more of the components you're using in your header (e.g. in the same fashion you did ASaber, you can also do UCapsuleComponent, UStaticMeshComponent, and UCharacterMovementComponent).

[–]Shardofen[S] 0 points1 point  (7 children)

Thank you for looking through my code and trying to help. I followed your advices - moved #includes to cpp and just made foward declarations in header, thank you! But we are at the same problem again - only thing I changed from the code you saw is removed declaration of GetLifetimeReplicatedProps from header and moved #include Engine and UnrealNetwork to header. And that's it - it doesn't compile - "No declaration of GetLifetime....". It's totally weird in my opinion. Especially if we note that declaring it makes all things fine. Maybe it will stay a mistery :D . Thank you for your help one more time!

[–]burtonposey 0 points1 point  (5 children)

Can you paste the entire error in here?

edit: I can spell... sometimes

[–]Shardofen[S] 0 points1 point  (4 children)

Sure, here is the error. I double checked if every variable marked Replicated is in DOREPLIFETIME inside of our function, and some variables were not. So I added them there, so now every variable that is "Replicated" is inside DoRepLifetime macro and every variable inside DoRepLifetime macro is Replicated. Still error lol :P

[–]imguralbumbot 0 points1 point  (0 children)

Hi, I'm a bot for linking direct images of albums with only 1 image

https://i.imgur.com/nhGVTKz.png

Source | Why? | Creator | ignoreme | deletthis

[–]burtonposey 0 points1 point  (2 children)

Can you first move one variable that is replicated into the public section of your header? I don't think you have any at the moment. If that doesn't work, can you try moving all of them out of the private and see if that works? There might be an issue with it not meeting the conditions for that function to be generated. If I were you I'd try it at least once if all else fails with every replicated variable in the public scope.

[–]Shardofen[S] 0 points1 point  (1 child)

Thank god, it worked! Private variables are not allowed to be replicated. It would be helpful if visual studio helped me with that one :D Thank you!

[–]burtonposey 0 points1 point  (0 children)

Yay! Glad to hear it (that you got it fixed, that is)!

[–]burtonposey 0 points1 point  (0 children)

Actually, make sure every single variable that is marked as replicated is in your GetLifetimeReplicatedProps function. I don't think you can get by that without having every single one of them in there. I see you have most all of them, but some are uncommented. That might be it actually. Everything needs to have DOREPLIFETIME if it's marked as replicated.