是UE4的新手。现在,我正在上两个课。兵和角色类。我的OnComponentBeginOverlap动态在典当类中。这意味着我正在尝试从典当类中获取OtherActor。 OtherActor应该是ACharacter类。现在让我们看一下参数签名:
void Adenn_pawn::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool FromSweep, const FHitResult& SweepResult)
查看第二个参数。它定义了AActor类,但我不想访问它的父类。我可以使用AActor函数或属性。实际上,我想使用ACharacter,因为它是一个ACharacter类。关于将此“ OtherActor”强制转换为自己的类的任何想法。或如何更改为子类?
谢谢。
答案 0 :(得分:0)
您可以尝试使用OtherActor
函数将ACharacter*
强制转换为类型Cast
的变量。幸运的是,该函数将检查重叠的actor是否为ACharacter
类型,因此当您不确定OtherActor
是否为ACharacter
类型时,此方法很有用。您可以调用Cast
函数,并像这样对演员进行操作,
if (ACharacter* OtherCharacter = Cast<ACharacter>(OtherActor))
{
// do stuff with OtherCharacter
}
else
{
// OtherActor does not point to an object of type ACharacter
}