【问题标题】:UE4 Casting OtherActor on OnComponentBeginOverlapUE4 在 OnComponentBeginOverlap 上投射 OtherActor
【发布时间】:2020-07-09 21:12:42
【问题描述】:

我是 UE4 的新手。现在我正在碰撞两个班级。一个pawn和一个角色类。我的 OnComponentBeginOverlap 动态在 pawn 类中。这意味着我正在尝试从我的典当类中获取 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”作为自己的类的任何想法。或者我怎样才能更改为子类?

提前致谢。

【问题讨论】:

  • Cast<ACharacter>(OtherActor) ?

标签: c++ unreal-engine4


【解决方案1】:

您可以尝试使用Cast 函数将OtherActor 转换为ACharacter* 类型的变量。幸运的是,该函数将检查重叠的演员是否为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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 2015-08-09
    • 1970-01-01
    • 1970-01-01
    • 2015-11-30
    • 2019-01-03
    • 1970-01-01
    相关资源
    最近更新 更多