To present my problem, here is entire code chain, from start to finish (to point where it doesn’t work). I won’t paste entire code because it not all relevant.
So I start in Character class:
Header:
virtual void PostInitializeComponents() OVERRIDE;
/////TESTING ONLY
UPROPERTY(EditAnywhere, Category = "Abilities")
TSubclassOf<class AARPAbility> AbilityToUse;
UFUNCTION()
void SpawnDefaultAbility();
UPROPERTY(Replicated)
class AARPAbility* AbilityInInventory;
void EquipAbility(class AARPAbility* AbilityIn);
UFUNCTION(Server, Reliable, WithValidation)
void ServerEquipAbility(class AARPAbility* AbilityIn);
void SetCurrentAbility(class AARPAbility* AbilityIn);
///////////////////////////////////////////////////////////////
///////::: Input Handling
protected:
UPROPERTY(Transient, ReplicatedUsing = OnRep_ActionButtonOne)
class AARPAbility* ActionButtonOne;
UFUNCTION()
void OnRep_ActionButtonOne();
UFUNCTION()
void InputActionButtonOne();
Implementation:
void AARCharacter::PostInitializeComponents()
{
Super::PostInitializeComponents();
if (Role == ROLE_Authority)
{
SpawnDefaultAbility();
}
}
void AARCharacter::SpawnDefaultAbility()
{
if (Role < ROLE_Authority)
return;
if (AbilityToUse)
{
FActorSpawnParameters SpawnInfo;
SpawnInfo.bNoCollisionFail = true;
AARPAbility* abilityTemp = GetWorld()->SpawnActor<AARPAbility>(AbilityToUse, SpawnInfo);
AbilityInInventory = abilityTemp;
if (AbilityInInventory)
{
EquipAbility(AbilityInInventory);
}
}
}
void AARCharacter::EquipAbility(class AARPAbility* AbilityIn)
{
if (AbilityIn)
{
if (Role == ROLE_Authority)
{
SetCurrentAbility(AbilityIn);
}
else
{
ServerEquipAbility(AbilityIn);
}
}
}
void AARCharacter::ServerEquipAbility_Implementation(class AARPAbility* AbilityIn)
{
EquipAbility(AbilityIn);
}
bool AARCharacter::ServerEquipAbility_Validate(class AARPAbility* AbilityIn)
{
return true;
}
void AARCharacter::SetCurrentAbility(class AARPAbility* AbilityIn)
{
ActionButtonOne = AbilityIn;
}
void AARCharacter::OnRep_ActionButtonOne()
{
SetCurrentAbility(ActionButtonOne);
}
void AARCharacter::GetLifetimeReplicatedProps(TArray< class FLifetimeProperty > & OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AARCharacter, AbilityInInventory);
DOREPLIFETIME(AARCharacter, ActionButtonOne);
}
void AARCharacter::InputActionButtonOne()
{
if (ActionButtonOne)
{
UARActionStateComponent* comp = ActionButtonOne->FindComponentByClass<UARActionStateComponent>();
if (comp)
{
ActionButtonOne->InputPressed();
}
}
}
To this point replication works just fine. Because I can call ActionButtonOne from client.
And this bring us to next class:
AARPAbility
Header:
UCLASS(hidecategories = (Input, Movement, Collision, Rendering, "Utilities|Transformation"), MinimalAPI, Blueprintable, notplaceable)
class AARPAbility : public AActor
{
GENERATED_UCLASS_BODY()
UPROPERTY(Replicated)
bool BlankRep;
virtual void Tick(float DeltaSeconds) OVERRIDE;
virtual void InputPressed();
UFUNCTION(BlueprintNativeEvent, Category = "Ability")
void AbilityInitialized();
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "State")
TSubobjectPtr<class UARActionStateComponent> ActionState;
};
Implementation:
AARPAbility::AARPAbility(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
bReplicates = true;
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true;
PrimaryActorTick.bAllowTickOnDedicatedServer = true;
ActionState = PCIP.CreateDefaultSubobject<UARActionStateComponent>(this, TEXT("ActionState"));
ActionState->SetNetAddressable();
ActionState->SetIsReplicated(true);
}
void AARPAbility::GetLifetimeReplicatedProps(TArray< class FLifetimeProperty > & OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(AARPAbility, BlankRep);
}
void AARPAbility::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
ActionState->TickMe(DeltaSeconds);
}
void AARPAbility::InputPressed()
{
//ActionState->StartAction();
if (Role < ROLE_Authority)
{
AbilityInitialized();
ActionState->ServerCreateActionState();
}
}
void AARPAbility::AbilityInitialized_Implementation()
{
}
InputPressed() function will try to call this function in Component:
UFUNCTION(Server, Reliable, WithValidation)
void ServerCreateActionState();
void UARActionStateComponent::ServerCreateActionState_Implementation()
{
if (ActionStateClass)
{
CurrentState = ConstructObject<UARActionState>(ActionStateClass);
}
}
bool UARActionStateComponent::ServerCreateActionState_Validate()
{
return true;
}
But when I set Break Point inside ServerCreateActionState_Implementation(), it is never reached. So I assume it is never executed.
I run it in editor, using dedicated server (2 clients). And I’m using source build 4.2,
Now the question is, what I’m doing wrong here ?