if it is on tick which i’m assuming it is. It will run over and over and over to check did you hit the button. Then it will run that function every time it is ticked. Yeah i read where the client can have
ROLE_Authority over the over actors in some cases. This must be the case as that how your code is acting.
Why would you want a client having authority over a function when it should be server controlled. If you are wanting the client to just run stop jump one time not over and over and over, then i would try this. This is your original code from epic, ok
// Detect change in jump press on the server <I'M ASSUMING THIS IS EPICS COMMENT?
if (CharacterOwner->GetLocalRole() == ROLE_Authority)// This is not doing what they are wanting the client has authority
{
const bool bIsPressingJump = CharacterOwner->bPressedJump;
UE_LOG(LogTemp, Warning, TEXT("bIsPressingJump: %s, bWasPressingJump: %s"), bIsPressingJump ? TEXT("true") : TEXT("false"), bWasPressingJump ? TEXT("true") : TEXT("false"));
if (bIsPressingJump && !bWasPressingJump)
{
CharacterOwner->Jump();
}
else if (!bIsPressingJump)
{
CharacterOwner->StopJumping();
}
}
If you read their comment it suppose to be server controlled. But its not. So Lets try this.
// Detect change in jump press on the server
if (GetNetMode() != NM_Client)//SHOULD ONLY LET THE SERVERS THRU
{
const bool bIsPressingJump = CharacterOwner->bPressedJump;//WHEN THIS CHANGES REPLICATE IT TO THE CLIENT
UE_LOG(LogTemp, Warning, TEXT("bIsPressingJump: %s, bWasPressingJump: %s"), bIsPressingJump ? TEXT("true") : TEXT("false"), bWasPressingJump ? TEXT("true") : TEXT("false"));
if (bIsPressingJump && !bWasPressingJump) //SERVER SHOULD RUN THIS NOT NO CLIENTS, LET CLIENTS RUN THE REPLICATION SECTION SO THEY GET ONE RUN NOT MULTIPLE
{
CharacterOwner->Jump();
}
else if (!bIsPressingJump)
{
CharacterOwner->StopJumping();
}
}
Then add in the replication code from above and if that if (GetNetMode() != NM_Client) works right the client will not get into it, but when the server rolls thru and changes that bool bIsPressingJump then the client should get his copy and run the function void YOURCLASS::OnRep_IsPressingJump() and the client should run it once.
Which ever way the var has been set it should run function void YOURCLASS::OnRep_IsPressingJump() then run its if or else to determine what the clients going to do. This is if the if (GetNetMode() != NM_Client) code works like it should.
I would have to make a test project to verify this all. I’m in the middle of moving over around 10k lines of code and debugging them. So i can not add this into my project yet and try it.
If what you are saying is true. I do not believe you need to be running stop jump after it has ran once. That is all its doing it just setting it to false which does not change that vars value. It stays the same so it just running code that really does not need rerun.
Just remember this. Any time you replicate a var the value must change for it to actually replicate to the client. If it is a false and you set it to false again it will not replicate again as the value did not change, It is the same. It will replicate when it goes to true. < different value.
This needs fixed, i have a bunch of code that uses this check. if(GetLocalRole() == ROLE_Authority) and none of it is working right as it thinks the client should have authority when he should not have it. OMG this is just wonderful.
I just peeked at the define of GetLocalRole() there is also a GetRemoteRole().
/** Returns whether this actor has network authority */
bool HasAuthority()
/** Returns how much control the local machine has over this actor. */
GetLocalRole()
/** Returns how much control the remote machine has over this actor. */
GetRemoteRole().
you can use this to test what your net mode is bool IsNetMode(ENetMode Mode)
You can use this to find out if the function is ticked bool IsActorTickEnabled()//forget this it is for an actor and yours is a extension of uobject
Edit: add these log lines into the function right above the if
if (CharacterOwner->GetLocalRole() == ROLE_Authority)
//or this one which ever you are using.
if (GetNetMode() != NM_Client)/
ADD THESE LOGS
UE_LOG(LogCharacterMovement, Log, TEXT("UCharacterMovementComponent::UpdateFromCompressedFlags are we NM_Client = %s"), IsNetMode(NM_Client) ? TEXT("TRUE") : TEXT("FALSE"));
UE_LOG(LogCharacterMovement, Log, TEXT("UCharacterMovementComponent::UpdateFromCompressedFlags are we NM_ListenServer = %s"), IsNetMode(NM_ListenServer) ? TEXT("TRUE") : TEXT("FALSE"));
UE_LOG(LogCharacterMovement, Log, TEXT("UCharacterMovementComponent::UpdateFromCompressedFlags are we NM_Standalone = %s"), IsNetMode(NM_Standalone) ? TEXT("TRUE") : TEXT("FALSE"));
UE_LOG(LogCharacterMovement, Log, TEXT("UCharacterMovementComponent::UpdateFromCompressedFlags are we NM_DedicatedServer = %s"), IsNetMode(NM_DedicatedServer) ? TEXT("TRUE") : TEXT("FALSE"));
UE_LOG(LogCharacterMovement, Log, TEXT("UCharacterMovementComponent::UpdateFromCompressedFlags CharacterOwner->HasAuthority() = %s"), CharacterOwner->HasAuthority() ? TEXT("TRUE") : TEXT("FALSE"));
from all this you should be able to solve this and get it running like you want.
I am very curious to see what your logs show.
Here is a link to Character Movement Component | Unreal Engine Documentation