【问题标题】:UE4 C++ how to call method from UChildActorComponent?UE4 C++ 如何从 UChildActorComponent 调用方法?
【发布时间】:2022-08-15 20:40:39
【问题描述】:
UPROPERTY(Category=Weapon,EditAnywhere,meta=(AllowPrivateAccess=\"true\"))
UChildActorComponent*ClientWeapon;

UPROPERTY(VisibleAnywhere,Category=\"Weapon\")
TSubclassOf<AWeaponBaseClient> WeaponClientClass;

UPROPERTY(VisibleAnywhere,Category=\"Weapon\")
TSubclassOf<AWeaponBaseServer> WeaponServerClass;

UPROPERTY(Category=Weapon,EditAnywhere,Replicated,meta=(AllowPrivateAccess=\"true\"))
UChildActorComponent*ServerWeapon;

这是 UChildActorComponent 由 headfile 创建。

ClientWeapon->SetChildActorClass(WeaponClientClass);

ServerWeapon->SetChildActorClass(WeaponServerClass);

ClientWeapon->CreateChildActor();

ServerWeapon->CreateChildActor();

在 cpp 文件的构造函数中,我初始化了 UChildActorComponent。

现在我需要来自 ClientWeapon 的调用函数,你能告诉我如何投射到 ClientWeapon->GetChildActor 吗?

    标签: c++ casting unreal-engine4


    【解决方案1】:

    ClientWeaponUChildActorComponent

    要访问您的 Actor,您需要从组件中获取子 Actor,然后将其转换为您的类

    AActor* ChildActor = ClientWeapon->GetChildActor();
    
    WeaponClientClass* WeaponActor = Cast<WeaponClientClass>(ChildActor);
    
    if (WeaponActor != nullptr) {
     // Now you can use your Weapon Actor
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-18
      • 1970-01-01
      • 1970-01-01
      • 2013-01-26
      • 1970-01-01
      • 2012-04-29
      • 1970-01-01
      • 2013-06-19
      相关资源
      最近更新 更多