So I was trying to make a projectile damage system. I have my Projectile, my own Character, and one Health Component one Damage Component as Actor component for Character to attach.
I tried to Cast the OtherActor in the OnHit() from projectile class. But it lost the informations I have in the Character’s Health component.
I know Cast a Generic class to Derived class will lost information but I guess I don’t want to alter OnHit. What can I do instead of that?
what do you mean by “lose the information” when you cast say
Cast<AMyCharacter>(HitResult.GetActor()) you don’t lose things you gain the additional context of the specific class you are now looking at (please keep in mind that you could check that the if(HitResult.GetActor() != nullptr) first)
if you AMyCharacter has a member function TakeDamage() then you would need to cast to the character in order to call that function (unless it is part of the virtual function table then you just need to try and cast high enough to where the function first exists)
if health is a UActorComponent then do you need to cast to the Character in order to call a specific function, couldn’t you just do HitResult.GetActor().GetComponent() (as healthComponent is probably not a USceneComponent you can’t Hit that component to test that)
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.