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

avatar image

16 2 7 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

avatar image

831 21 4 29

avatar image BaconGaming97 Apr 22 '17 at 12:33 AM

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.

avatar image Benergy Apr 22 '17 at 10:01 AM

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

avatar image BaconGaming97 Apr 22 '17 at 05:12 PM

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

avatar image BaconGaming97 Apr 23 '17 at 04:08 AM

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

avatar image Benergy Apr 23 '17 at 06:41 AM

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?

avatar image BaconGaming97 Apr 23 '17 at 01:52 PM

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

avatar image BaconGaming97 Apr 28 '17 at 03:01 AM

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

avatar image Benergy Apr 28 '17 at 06:33 AM

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".

avatar image BaconGaming97 Apr 30 '17 at 03:59 AM

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

avatar image BaconGaming97 Apr 29 '17 at 04:51 AM

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

avatar image Benergy Apr 30 '17 at 07:25 AM

You can print the enum with the method described here https://answers.unrealengine.com/questions/52622/logging-enums-ie-role.html

avatar image BaconGaming97 May 03 '17 at 01:46 AM

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.

avatar image BaconGaming97 May 03 '17 at 02:46 AM

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.

avatar image Benergy May 03 '17 at 07:10 AM

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?

avatar image BaconGaming97 May 03 '17 at 11:11 AM

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.

avatar image Benergy May 03 '17 at 12:59 PM

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.

avatar image BaconGaming97 May 03 '17 at 01:47 PM

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.

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