I’ve been trying to create a rudimentary Zelda clone to practice my skills and am getting hung up here.
I have a sword weapon with a box collider I added so I could adjust the hitbox if needed.
SwordHitbox = FindComponentByClass<UBoxComponent>();
if (SwordHitbox != nullptr) {
SwordHitbox->SetSimulatePhysics(true);
SwordHitbox->SetNotifyRigidBodyCollision(true);
SwordHitbox->BodyInstance.SetCollisionProfileName("BlockAllDynamic");
SwordHitbox->OnComponentHit.AddDynamic(this, &ASwordWeapon::OnCompHit);
UE_LOG(LogTemp, Warning, TEXT("Hey looks like you got a hitbox"));
}
This is how I am attempting to set it up in the constructor. At this stage, I am merely trying to get past my nullptr check. I’ve tried several methods for retrieving the UBoxComponent but have had no luck. What am I missing about how this works?