Download

Server RPC function not working as intended?

Im making an RPC function that can hold actions. Such as dodge, sprint, attack, etc. I’ve made an enum that is a bitmask to conserve memory and ive made a new player controller so everyone could have it and so that my actor file isnt so clogged. Everything would be in the playercontroller file. So i did all this and so far im starting off with what should be the easiest… “sprint” i created the start sprint in my character function and i made a pointer to my player controller -which im starting to think i should just put the startsprint input in the player controller too, but we’ll see to whoever responds to this- and im either getting nothing my character stays walking or i get that my characrter tries to start running but the sever isnt allowing the character to change run speeds so its locking it at walk and all i see is the client attempting to run but not on the server. (ill link code and what not). Anyway, ive been trying to get used to bitmasks and bitflags and i thought i had it, maybe im doing something wrong. I thought i had everything right, but clearly sometihing is up! lol. I think it has something to do with the pointers or maybe the flags arent turning on correctly but we will see. Any help is appreciated!

ill have a video when it uploads. As of now, here is the code… the important parts.
UPDATE : video link
https://www.youtube.com/watch?v=FynrGGDy9MY&feature=youtu.be

PlayerControllerCustom.h

#define TEST_BIT(Bitmask, Bit) (Bitmask &  static_cast<uint32>(Bit))

#define SET_BIT(Bitmask, Bit) (Bitmask |= static_cast<uint32>(Bit))

#define CLEAR_BIT(Bitmask, Bit) (Bitmask &= ~( static_cast<uint32>(Bit)))




UENUM(BlueprintType, meta = (Bitflags, UseEnumValuesAsMaskValuesInEditor = "true"))

enum class EMovementCallFlags : uint8

{

    Dodging = 1,

    Sprinting = 2,

    Attacking = 4,

    Blocking = 8,

};

ENUM_CLASS_FLAGS(EMovementCallFlags)

PlayerControllerCustom.cpp

bool APlayerControllerCustom::DoAction_Validate()
{
    if (Attributes.RunSpeed < Attributes.MaxPlayerSpeed())
    {
        return true;
    }
    else return false;
}
void APlayerControllerCustom::DoAction_Implementation()
{
    MultiCastAction();
}

void APlayerControllerCustom::MultiCastAction_Implementation()
{
    Sprint();
}
void APlayerControllerCustom::Sprint()
{

        if(TEST_BIT(MovementCallFlags, EMovementCallFlags::Sprinting))
    {
        TObjectIterator<APlayerCharacter>PlayerCharacter;
        if(!PlayerCharacter) return;

        PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = Attributes.RunSpeed;

        PlayerCharacter->UpdateStamina();


            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow,
                        TEXT("SPRINTINGGGGGG"));

        }
    else {
        TObjectIterator<APlayerCharacter>PlayerCharacter;
        if(!PlayerCharacter) return;
        PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = Attributes.WalkSpeed;
        PlayerCharacter->UpdateStamina();

        GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("WALKING"));

        }
}

PlayerCharacter.CPP

void APlayerCharacter::StartSprint()
{
    if (Role < ROLE_Authority)
    {
        if (ControllerRef != nullptr){

        SET_BIT(ControllerRef->MovementCallFlags, EMovementCallFlags::Sprinting);

        ControllerRef->DoAction();
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("SPRINT TRUE"));
            if(TEST_BIT(ControllerRef->MovementCallFlags, EMovementCallFlags::Sprinting))
            {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("FLAG IS TRUE"));

            }

        }

    }

}
void APlayerCharacter::StopSprint()
{
    if (Role < ROLE_Authority)
    {
        if (ControllerRef != nullptr ){

            CLEAR_BIT(ControllerRef->MovementCallFlags, EMovementCallFlags::Sprinting);

            ControllerRef->DoAction();
       GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("SPRINT FALSE"));
        }
    }
}

Anyone out there? :confused:

Have you been successful in getting RPC calls from the client to the server and then from the server to the client working properly? Have you gotten sprint to work without optimizing it? I would do that first. There are several examples of sprinting I have come across in my long journey of learning this beast of an engine.

@acxsasx yes i have! I have done so before from passing by reference. Sprinting was working properly then I thought of an awesome idea to set everything to one function so i dont have to then create a server function for ever other thing i wanna do in my game. So now here i am lol.

@Matgarciaz Cool! I get what you are trying to do. Afraid I am not much help at the moment. I am still getting familiar with making it work let alone optimizing it yet. Doing a lot of


   UE_LOG(AWGeneralLog, Warning, TEXT("%s() NetMode: %s"), TEXT(__FUNCTION__), IsNetMode(NM_Client) ? TEXT("Client") : IsNetMode(NM_DedicatedServer) ? TEXT("Dedicated Svr") : TEXT("Other"));

in my methods to see where things are happening and gaining a new appreciation for this post, https://docs.unrealengine.com/en-US/Gameplay/Networking/Actors/RPCs/index.html.