I have a class(AMATTER
), its child class(AWEAPON
), and its grandchild class(Asword
). The method in the child class isn’t being executed, no matter what!!!
class MY_MOBA_API Asword : public AWEAPON
{
GENERATED_BODY()
protected:
virtual void BeginPlay() override;
virtual void OnOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override;
virtual void EndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) override;
virtual void __operate_on_hit_actor_from_array(AActor* hit_actor) override;
};
class MY_MOBA_API AWEAPON : public AMATTER
{
GENERATED_BODY()
protected:
virtual void BeginPlay() override;
virtual void __operate_on_hit_actor_from_array(AActor* hit_actor) override;
virtual void OnOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override;
virtual void EndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) override;
};
class MY_MOBA_API AMATTER : public AActor
{
GENERATED_BODY()
// .........
// METHODS
protected:
virtual void __operate_on_hit_actor_from_array(AActor* hit_actor);
void __clear_hit_actor_array() { __hit_actor_array.Empty(); }
virtual void OnOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
virtual void EndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
public:
UFUNCTION(BlueprintCallable)
virtual void initalize_on_possess(AActor* owning_actor);
UFUNCTION(BlueprintCallable)
AActor* get_owner_actor() { return __owner_actor; }
UFUNCTION(BlueprintCallable)
UAbilitySystemComponent * get_owner_ability_system_component()
{ return __owner_ASC; }
};
The above are header files of AMATTER, its child AWEAPON, and its grandchild Asword.
void Asword::BeginPlay()
{
Super::BeginPlay();
}
void Asword::OnOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
Super::OnOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
}
void Asword::EndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
Super::EndOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex);
}
void Asword::__operate_on_hit_actor_from_array(AActor* hit_actor)
{
UE_LOG(
LogTemp,
Warning,
TEXT("Asword::__operate_on_hit_actor_from_array => ")
);
Super::__operate_on_hit_actor_from_array(hit_actor);
UAbilitySystemComponent* hit_actor_ASC_ = UAbilitySystemBlueprintLibrary::GetAbilitySystemComponent(hit_actor);
if ( !(
hit_actor_ASC_ &&
__owner_ASC
) ) return;
if (!hit_actor_effect_class) return;
FGameplayEffectContextHandle effect_context_handle = __owner_ASC->MakeEffectContext();
effect_context_handle.AddSourceObject(__owner_actor);
const FGameplayEffectSpecHandle hit_effect_spec_handle_ = __owner_ASC->MakeOutgoingSpec(
hit_actor_effect_class,
1.f,
effect_context_handle
);
__owner_ASC->ApplyGameplayEffectSpecToTarget(
*hit_effect_spec_handle_.Data.Get(),
hit_actor_ASC_
);
}
The above is the implementation of the sword methods.
void AWEAPON::BeginPlay()
{
Super::BeginPlay();
}
void AWEAPON::__operate_on_hit_actor_from_array(AActor* hit_actor)
{
Super::__operate_on_hit_actor_from_array(hit_actor);
}
void AWEAPON::OnOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
Super::OnOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
if (__hit_actor_array.Contains(OtherActor)) return;
__hit_actor_array.Add(OtherActor);
__operate_on_hit_actor_from_array(OtherActor);
}
void AWEAPON::EndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
Super::EndOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex);
}
The above is the implementation of AWEAPON methods.
void AMATTER::__operate_on_hit_actor_from_array(AActor* hit_actor)
{
}
void AMATTER::OnOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
}
void AMATTER::EndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
}
The above is the implementation of AMATTER methods.
Basically, OnOverlap method calls __operate_on_hit_actor_from_array. Asword is the object in the world.
OnOverlap method works. When code reaches __operate_on_hit_actor_from_array, it executes parent and grandparent class, not Asword.
I am unable to execute the
void Asword::__operate_on_hit_actor_from_array(AActor* hit_actor)
method, even if sword is the only object in the world.
If I use a debugger, it executes AWEAPON
and AMATTER
methods - __operate_on_hit_actor_from_array
, not Asword.
What is the error? How to resolve?