[4.6.1] How to enable any Actor class to send RPCs like Player Controller Does? GameState for example

Dear Epic,

In 4.6.0-1, I am unable to get a client-side Game state to send a UFUNCTION(Reliable,Server,WithValidation) function call to the server.

So to be clear, the server can call the function just fine, but the client cannot

It seems that the only two classes where the client can send server function calls back to the server are PlayerController and Character.

Why is this so?

I really need to enable custom actor classes to have client->server communication!

#.h

UCLASS()  
class AGameWorld : public AGameState
{
	GENERATED_BODY()
public:
	AGameWorld(const FObjectInitializer& ObjectInitializer);


  /** overridden to return that player controllers are capable of RPCs */
	virtual bool HasNetOwner() const override;

      UFUNCTION(Reliable,Server,WithValidation)
     void SERVER_Test(); 
};

#.cpp

bool AGameWorld::HasNetOwner() const
{
	return true;  
}

bool AGameWorld::SERVER_Test_Validate()
{ 
	return true;
}
void AGameWorld::SERVER_Test_Implementation()
{ 
	UE_LOG(Joy,Error,TEXT("GAMEWORLD ~ SERVER ~ GAMEWORLD FUNC RAN"));
} 

void AGameWorld::Tick(float DeltaTime)
{ 
	Super::Tick(DeltaTime);
	//~~~~~~~~~~~~
	 
	if(!HasAuthority())
	{    
		UE_LOG(Joy,Error,TEXT("GAMEWORLD ~ CLIENT ~ GAMEWORLD FUNC RAN"));
		SERVER_Test();  
	}   
}

#What Happens

In the above code, the UE_LOG runs for the client, but the UE_LOG that is inside the server call does not run

As I mentioned, in 4.3 and during the Beta, I could easily send messages from the client to the server using the Game State Class

#Custom Actor Classes

How can I enable custom actor classes to send messages from client to server

#NetOwner

I tried putting the HasNetOwner() code in my custom actor class and in Game state, but that did not make the client able to send messages to the server.

#What Should I Do?

Thanks!

Rama

+1 I’d like to know how to enable a custom AActor to be able to send client->server RPCS?

Hi Rama,

The current design, and as far as I can tell, the design in 4.3 as well, is that only actors that are owned by a local PlayerController (and the PlayerController itself) can send Server RPCs. I’m not sure off hand why this was possible in 4.3, I’m investigating that now.

Technically, the reason the call is rejected even though HasNetOwner is overridden, is that AActor::GetNetConnection is probably returning null when invoked on your game state class (the game state won’t have its Owner property set).

The typical solution, and what we generally do for our internal projects, is route the server RPCs through the PlayerController or its Pawn. RPCs sent from local PlayerState objects should work as well, since their owner is set to the corresponding PlayerController.

You can experiment with overriding GetNetConnection as well, but we haven’t tested this and it may have unknown consequences!

To help track down what was happening in 4.3, I’d be curious to know whether a non-null Connection was being returned from Actor->GetNetConnection() in UIpNetDriver::ProcessRemoteFunction for the GameState function. If so, this implies the GameState’s Owner was set somewhere - it’d be good to know if AActor::SetOwner was being called on it.

Dear Ryan,

Thank you for the response Ryan!

I wrote this:

“As I mentioned, in 4.3 and during the Beta, I could easily send messages from the client to the server using the Game State Class”

Sorry I mis-remembered how I did my chat system in 4.3, I was actually routing the RPCs thru PlayerController as you are mentioning is standard practice.

It is good to know about PlayerState being viable for RPCs as well, I will look into this!

#Thought For Epic ~ Game State RPCs

Any thoughts on enabling Game State to support RPCs directly? It would make the Game State a more powerful network class :slight_smile:

#:heart:

Rama