x

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"

AnswerHub Maintenance

Background maintenance is scheduled to occur between 9 - 11am EDT on Tuesday, May 21. Site operation may be slower than normal during this time and a brief interruption in operation may be observed

Why is a Server function on component not being called?

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 ?

Product Version: Not Selected
Tags:
more ▼

asked Jun 06 '14 at 11:55 AM in C++ Programming

avatar image

iniside
1.6k 102 97 181

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

I will answer myself. The issue as it happens was very trivial.

Ability actor just didn't had any owner. So It didn't know it could be affected by my Character.

So if you have similar issue. Make sure that actor is owned by something.

more ▼

answered Jun 07 '14 at 08:16 AM

avatar image

iniside
1.6k 102 97 181

avatar image envenger Dec 17 '14 at 09:02 PM

You answer really helped me. I didn't knew something like that even existed.

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