I’m explicitly setting a UObject property in a server RPC and it’s not getting set. Server_AssignTeam is firing but “MyTeam” is never set. My Character is like so:
Project:
UCLASS()
class TEAMGAME_API ATeamGameCharacter
: public ATeamGameCharacterBase
{
GENERATED_BODY()
public:
UPROPERTY(ReplicatedUsing = OnRep_Team)
UTeam* MyTeam;
UFUNCTION()
void OnRep_Team();
UFUNCTION(server, reliable, withvalidation)
void Server_AssignTeam(ATeamGameCharacter* InCharacter);
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
virtual void Tick(float DeltaSeconds) override;
protected:
virtual void BeginPlay();
};
And my cpp:
void ATeamGameCharacter::Server_AssignTeam_Implementation(ATeamGameCharacter* InCharacter)
{
ATeamGameGameMode* GameMode = Cast<ATeamGameGameMode>(UGameplayStatics::GetGameMode(this));
InCharacter->MyTeam = GameMode->RedTeam;
}
void ATeamGameCharacter::Tick(float DeltaSeconds)
{
if (MyTeam != nullptr)
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, TEXT("Team is set"));
}
void ATeamGameCharacter::BeginPlay()
{
Server_AssignTeam(this);
}
edit: The second problem is that OnRep_Team never gets called.