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"

UFUNCTION(Server) does not have ROLE_Authority

Hello! I am having an issue on only a single class. It seems that my ServerInteract() is not actually calling the Interact function which is multicast from the server as the Item is not being destroyed unless I toggle off the dedicated server and I am the server. here is my code:

         void AttemptInteract();
         UFUNCTION(Reliable, NetMulticast, WithValidation)
         void Interact();
         UFUNCTION(Reliable, Server, WithValidation)
         void ServerInteract();
         void ServerInteract_Implementation();
         bool ServerInteract_Validate();
     void APlayerControlledCharacter::AttemptInteract() {
         if (Role < ROLE_Authority) {
         else {
     void APlayerControlledCharacter::Interact_Implementation() {
         if (PlayerLookingAt) {//if != NULL
             if (dynamic_cast<AItem*>(PlayerLookingAt)) {//!= NULL
                 AItem* Item = dynamic_cast<AItem*>(PlayerLookingAt);
                 FString ItemName = Item->ItemName;
                 if (!PlayerInventory->IsInventoryFull) {//this is false becasue everything else in the function works
                     Item->Destroy();//this is not being destroyed for clients unless I do NOT run a dedicated server
                     if (GEngine)
                         GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Cyan, TEXT("Picked Up " + ItemName));
                 else {
                     if (GEngine)
                     GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Cyan, TEXT("Cannot Pickup Inventory FULL"));
                 if (GEngine) {
                     GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Cyan, TEXT("Interact Called"));
     void APlayerControlledCharacter::ServerInteract_Implementation() {

Product Version: UE Github Master branch
more ▼

asked Apr 21 '17 at 11:56 AM in C++ Programming

BaconGaming97 gravatar image

1 1

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Actually, clients are not allowed to destroy actors unless they spawned them. The typical procedure would be:

  1. Server spawns new item

  2. New item is replicated to the clients, which spawn a local copy each

  3. Server destroys the item

  4. The item's local copies are destroyed on each client

If a client tries to destroy an actor that it has not the authority for this destroy request is ignored. So in your case I would guess that you have a problem with replication and authority concerning your items.

more ▼

answered Apr 21 '17 at 04:17 PM

Benergy gravatar image

306 11 3 15

BaconGaming97 gravatar image BaconGaming97 5 days ago

the item was dragged in manually in the editor for testing purposes, it is my understanding that it is created from the server in this case.

Benergy gravatar image Benergy 4 days ago

Yes, that should be the case. So the messages from code line 29 and 36 are printed two times each? Also, I don't think that you need to declare ServerInteract_Implementation and ServerInteract_Validation in your header - this should be done by the UFUNCTION macro. And have you provided implementations of both validation functions (for ServerInteract and Interact)?

BaconGaming97 gravatar image BaconGaming97 4 days ago

if they are true then they print once, otherwise they don't it works as intended. both validation functions are implemented, but they just return true for testing purposes

BaconGaming97 gravatar image BaconGaming97 4 days ago

It should also be noted that I have tested if(Role == ROLE_Authority) and it never works on this particular function even though it is a server function, while other functions with the same macro that if statement evaluates to true. I don't know what causes this

Benergy gravatar image Benergy 4 days ago

Okay, so when I understand this correctly, then Role==ROLE_AUTHORITY evaluates to false when you check it in ServerInteract_Implementation? This can mean, that you spawned your character locally on the client and not on the server. This way your client has the authority over your character. How do you spawn your character?

BaconGaming97 gravatar image BaconGaming97 3 days ago

via a player start in the level and the gamemode blueprint's default pawn is my PlayerControlledCharacter blueprint that is derived from my playercontrolledcharacter c++ class

(comments are locked)
10|2000 characters needed characters left
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