Hi guys,
I have to code the multiplayer part of our project, for that I have read several posts and documentations, and now I would like to test what I have read.
First step : Replication of a simple variable. I would like to sync a simple int32 from the server to the client.
I have created a new test project based on the third person template. I have tested the generated code and it's works fine. I see both players, sync on the server and on the client.
To test variable replication I have added this in my TestNetworkCharacter.h
And this to my TestNetworkCharacter.cpp
I have added #include "Net/UnrealNetwork.h" in the TestNetwork.h
To test if the client receive the new value when the server change it, I have added this 2 actions in the .cpp.
This to change the value
And this to log the current value
Test procedure :
1) I launch the server and next the client.
2) I hit the key to execute Action1() on server and next on the client, this is to log the current value of my variable.
3) On the server I hit the key to execute Action2(), this normaly change the value to 2, and replicated it to the client.
4) I repeat the step 2 to log the new value.
But when I read the server's log I see
And I see this in the client's log
The value is still on 1 on the client. Replication dont have to change the value of my variable to 2 on the client ?
Where is the error ?
Thanks you for your reply.
I have to code the multiplayer part of our project, for that I have read several posts and documentations, and now I would like to test what I have read.
First step : Replication of a simple variable. I would like to sync a simple int32 from the server to the client.
I have created a new test project based on the third person template. I have tested the generated code and it's works fine. I see both players, sync on the server and on the client.
To test variable replication I have added this in my TestNetworkCharacter.h
Code:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Replicated, Category = Testing) int32 Test;
Code:
void ATestNetworkCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME(ATestNetworkCharacter, Test); }
To test if the client receive the new value when the server change it, I have added this 2 actions in the .cpp.
This to change the value
Code:
void ATestNetworkCharacter::Action2() { if (Role == ROLE_Authority) Test = 2; }
Code:
void ATestNetworkCharacter::Action1() { FString MyString = FString::FromInt(Test); if (Role == ROLE_Authority) { UE_LOG(LogSomething, Log, TEXT("Server %s"), *MyString); } else { UE_LOG(LogSomething, Log, TEXT("Client %s"), *MyString); } }
1) I launch the server and next the client.
2) I hit the key to execute Action1() on server and next on the client, this is to log the current value of my variable.
3) On the server I hit the key to execute Action2(), this normaly change the value to 2, and replicated it to the client.
4) I repeat the step 2 to log the new value.
But when I read the server's log I see
Code:
[2014.04.21-14.47.18:015][315]LogSomething: Serveur 1 [2014.04.21-14.47.24:864][579]LogSomething: Serveur 2
Code:
[2014.04.21-14.47.08:804][233]LogSomething: Client 1 [2014.04.21-14.47.28:621][981]LogSomething: Client 1
Where is the error ?
Thanks you for your reply.
Comment