[英]UE4 C++ how to call method from UChildActorComponent?
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;
this is UChildActorComponent Create by headfile.这是 UChildActorComponent 由 headfile 创建。
ClientWeapon->SetChildActorClass(WeaponClientClass);
ServerWeapon->SetChildActorClass(WeaponServerClass);
ClientWeapon->CreateChildActor();
ServerWeapon->CreateChildActor();
in cpp file,construction function,I initallize the UChildActorComponent.在 cpp 文件中,构造 function,我初始化 UChildActorComponent。
now I need call function from ClientWeapon,can you tell me how to cast to ClientWeapon->GetChildActor?现在我需要从 ClientWeapon 调用 function,你能告诉我如何投射到 ClientWeapon->GetChildActor 吗?
ClientWeapon
is a UChildActorComponent
. ClientWeapon
是一个UChildActorComponent
。
To access your Actor, you need to get the Child Actor from the component and then cast it to your class要访问您的 Actor,您需要从组件中获取子 Actor,然后将其投射到您的 class
AActor* ChildActor = ClientWeapon->GetChildActor();
WeaponClientClass* WeaponActor = Cast<WeaponClientClass>(ChildActor);
if (WeaponActor != nullptr) {
// Now you can use your Weapon Actor
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.