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:

    PlayerControlledCharacter.h
    	void AttemptInteract();
    	UFUNCTION(Reliable, NetMulticast, WithValidation)
    	void Interact();
    	UFUNCTION(Reliable, Server, WithValidation)
    	void ServerInteract();
    	void ServerInteract_Implementation();
    	bool ServerInteract_Validate();
PlayerControlledCharacter.cpp
    void APlayerControlledCharacter::AttemptInteract() {
    	if (Role < ROLE_Authority) {
    		ServerInteract();
    	}
    	else {
    		Interact();
    	}
    }
    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
    				PlayerInventory->AttemptAddItem(ItemName);
    				PlayerInventory->SaveInventory();
    				PlayerInventory->AttemptLoadInventory();
    				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() {
    	Interact();
    }

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.

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.

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)?

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

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

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?

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

are you unable to help me? I am still stuck with this issue

From my understanding the AddOnScreenDebugMessage calls should produce their output two times, one time for the server call and one time for the client call. You can also increase the information when you add the result of AActor::GetNetMode to each call.

Also, are your items replicated? Perhaps it helps when you set them to “Always Relevant”.

My Items are replicated. They are also always relevant. I triedGetNetMode() in a AddOnSceenDebugMessage() but was unable to do so because it is not a text and I could not find a way to alter it to a text

U don’t know if you get a notification if I dont reply so thats what this message is

You can print the enum with the method described here How can I output the value of an Enum to a log? - C++ - Unreal Engine Forums

sorry for late reply I have been working on other things in the meantime. I did more testing and concluded that I was wrong aboutwhat I intiially said when I told you it did not have authority.

I think I found my problem. I THINK. but I don’t see ant discernible way to fix it. I believe that the server function is not being called on the server because it is a client calling the server RPC and the object is onwed by the server. also IsPendingKill() returns false UNLESS I am the host and toggle off dedicated server.

Your APlayerControlledCharacter calls ServerInteract(), which is valid if APlayerControllerCharacter is controlled by the PlayerController assigned to the client.

So you can check HasNetOwner() – if false, that’s why ‘Server’ RPCs are not working.

But what I don’t understand is why your APlayerControlledCharacter should be destroyed when you run a standalone game?

the thing that gets destroyed is the Item the player picked up. It correctly adds to the inventory and saves, it just doesn’t destroy the item. HasNetOwner does return false. how should I work around this?
Also HasNetOwner() returns false even if I do play without the dedicated server as the host.

Does HasNetOwner() return false for the character or the item? Also, when I think of it, there is actually no need to make the interact function NetMulticast. I think it would be better to just change the item and the inventory on the server and let their status be replicated to the clients.

HasNetOwner() returns false on the Character I have not tested it ont he Item. what do you mean replicated to the clients. also I THINK I have figured out a bit more. This clas Called PlayerControlledCharacter is derived from ACharacter. I think that I need to make a PlayerController. I have never done neworking before and I believe this is a major issue caused from this. also I am not at my home pc so I can’t test anything right now.