I have this function to select a weapon
void AShooterCharacter::SelectWeapon(TSubclassOf<AWeapon> WeaponClass)
{
if (CurrentWeapon)
{
CurrentWeapon->Destroy(true);
}
CurrentWeapon = GetWorld()->SpawnActor<AWeapon>(WeaponClass);
CurrentWeapon->AttachToComponent(Mesh1P, FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true), TEXT("GripPoint"));
}
However I want to add a check so that if CurrentWeapon is of the same subclass as WeaponClass, I just return. What would be the solution to this? I was thinking that it could be possible to try to cast CurrentWeapon to the WeaponClass, but I’m not sure how to do that, since WeaponClass is a TSubClassOf?