Child AActor Server function not being called on server

Here is a strange one. I have an Actor Object that is set to replicate.

MyActor(const FObjectInitializer & objectInitializer):super(objectInitializer)
{
    this->SetReplicates(true)
}

My pawn has a pointer to it marked as replicate, it is initially set to null in the constructor.

UPROPERTY(Replicated)
MyActor * myActor;

On BeginPlay the Actor is spawned on the server and then replicated down to it’s owning client. That all seems to work properly.

My custom Actor has a function marked as a server function that when called I want it to request the server to change the value. This function is successfully called by the client, but never invokes on the server.

myActor.h

UFUNCTION()
void SetSomeValue(float value);

UFUNCTION(Server, Reliable, WithValidation)
void ServerSetSomeValue(float value);

myActor.cpp

void MyActor::SetSomeValue(float value)
{
    if(this->Role == ROLE_Authority)
    {
        this->someValue = value;
    }
    else
    {
        this->ServerSetSomeValue(value);
    }
}

void MyActor::ServerSetSomeValue_Implementation(float value)
{
    if(this->Role == ROLE_Authority)
    {
        this->SetSomeValue(value);
    }
}

bool MyActor::ServerSetSomeValue_Validate(float value)
{
    return true;
}

I’ve stepped through it in debug and for the life of me the function IS called on the client, but it NEVER gets called on the server.

Make sure your code has an overridden GetLifetimeReplicatedProps function, so the var will replicate correctly.

Heres an example of one:

void ASideOpCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);

	DOREPLIFETIME(ASideOpCharacter, bIsCrouching);
	DOREPLIFETIME(ASideOpCharacter, CoinsCollected);
}

Ive found that even with the RPC to set it on the server, you still need to have this.

HI @anonymous_user_9fbef36c I’ve got that setup with DOREPLIFETIME being called with the sub actor being passed to it… still RPC is not being called. When I add a RPC to the Character itself that then calls the child actor’s function that works, but no direct call on the child actor seems to work.

The only thing I could think of based off your code is your use of the “this” keyword. Since the “this” keyword works as a pointer, and you’re calling the functions on the character from the client, it might be failing the role authority check, as your using the pointer to the clients char. Granted, C++ should be smarter than this, but all of the code for UE4 never uses this->Role. Its always Role == Role_Authority. So try your code without “this” and see if it makes a difference, otherwise, the only other thing I can think of is it is failing the validation check.

That and i’ve had UE4 be picky about using “this” before.

Also, in your .h when declaring functions for Server make sure you explicitly declare the implementation versions. ie:

UFUNCTION(Server, Reliable, WithValidation)
void ServerRPCSetCrouch();
bool ServerRPCSetCrouch_Validate();
void ServerRPCSetCrouch_Implementation();

In the engine source, all of the times that an Implementation function is declared, they always declare all three of the functions in the h.

I’ve used “this” before without any problem in the past. For some reason it is only this Actor (Pawn & PlayerController work fine). I’ve been reading as much documentation on replication as I can trying to figure this out and nothing seems to work. It was originally a AInfo actor (if that helps) I changed it to a (AActor). I’ve done DOREPLIFETIME, I’ve even overloaded the ReplicateSubobjects function and past it in manually with no success (I’ve insured Set replicates to in the constructor a thousand times) . I currently have two theories and you just nailed one of them.

Theory 1:
I have ready a lot about “ownership” of actors via player controller. Currently my spawn Info structure has my character as the owner, which “should” route up to the owning character controller, but for somereason ownership of the actor is not being recognized…

Theory 2:
I was not explicitly declaring my Server functions in the header.

Update
Unfortunatly no dice on Theory 2, still not calling the server version.

Theory 3 (added)
Maybe there is something to “this”… going to try it. Thanks @anonymous_user_9fbef36c

No dice for Theory 3 either… removed “this” pointers still not replicating the function…

… Okay… so… I created a completely new actor… Hooked it up EXACTLY as I hooked up the last one… and it worked…

The only difference between the two actors is that the first was was originally created as an AInfo object (that I later changed to an AActor). In short… I have no !*%# clue, absolutely nothing… I have spent an entire weekend banging my head against a wall I still don’t understand and that frustrates me more… If I had figured out why that actor does not replicate I’d have been much happier…

I even tried setting it all back to see if something had simply “jogged” in the code with still no success on the original actor…

Well I think this was some sort of bazaar freak accident that some how caused a single actor to not work right but all the others work fine… I’m marking this resolved. How do you fix this… Create a new Actor and test it’s replication before moving forward…

Well I think this was some sort of bazaar freak accident that some how caused a single actor to not work right but all the others work fine… I’m marking this resolved. How do you fix this… Create a new Actor and test it’s replication before moving forward…