【发布时间】:2021-03-20 12:08:45
【问题描述】:
目前我有一个适合我的角色的课程,如下所示:
.h
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "DarkFantasies_MainCharacter_Base.generated.h"
class USpringArmComponent;
class UCameraComponent;
class ADarkFantasies_WeaponBase;
UCLASS()
class PROJECT_DF_API ADarkFantasies_MainCharacter_Base : public ACharacter
{
GENERATED_BODY()
public:
ADarkFantasies_MainCharacter_Base();
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera")
USpringArmComponent* SpringArmCom;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Camera")
UCameraComponent* CameraCom;
protected:
virtual void BeginPlay() override;
protected:
void MoveForward(float Value);
void MoveRight(float Value);
void TurnAtRate(float Value);
void LookUpAtRate(float Value);
void InteractPressed();
void LAttackPressed();
void HAttackPressed();
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
float BaseTurnRate;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
float BaseLookUpAtRate;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Interaction")
float TraceDistance;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Animations")
UAnimMontage* M_LightAttack;
UFUNCTION(BlueprintNativeEvent)
void TraceForward();
void TraceForward_Implementation();
public:
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon")
TSubclassOf<ADarkFantasies_WeaponBase> Weapon;
private:
AActor* FocusedActor;
};
请注意武器类型。 该武器是从我的武器的自定义通用类派生的自定义蓝图类,如下所示:
.h
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "DarkFantasies_WeaponBase.generated.h"
UCLASS()
class PROJECT_DF_API ADarkFantasies_WeaponBase : public AActor
{
GENERATED_BODY()
public:
ADarkFantasies_WeaponBase();
protected:
virtual void BeginPlay() override;
public:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Attributes")
float BaseDamage;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Attributes")
float AttackSpeed;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Mesh")
USkeletalMeshComponent* WeaponMesh;
};
现在我有另一个类,它将在我的武器骨架网格的插槽中放置一个跟踪器,以便稍后跟踪它的运动。我正在尝试通过该蓝图类调用该网格,如下所示:
Player = Cast<ADarkFantasies_MainCharacter_Base>(MeshComp->GetOwner());
if(Player)
{
Weapon = Player->Weapon->WeaponMesh; //error occurs here under WeaponMesh
ActorsToIgnore = { MeshComp->GetOwner() };
LastLocation1 = Weapon->GetSocketLocation("Trace1");
LastLocation2 = Weapon->GetSocketLocation("Trace2");
LastLocation3 = Weapon->GetSocketLocation("Trace3");
LastLocation4 = Weapon->GetSocketLocation("Trace4");
}
请注意,我在这个类中的 Weapon 变量是 USkeletalMeshComponent 类型,它与 Weapon_Base 类中的 WeaponMesh 相同。但是当我调用网格时,我得到错误 UClass 没有成员“WeaponMesh”。我该如何解决?
感谢您的帮助!
【问题讨论】:
-
我在您的代码中看到“WeaponMesh”的唯一情况是一次作为参数的标识符,一次是在没有上下文的 if 中尝试使用它时。这有帮助吗?如果没有,请提供minimal reproducible example。
-
嗨@Yunnosch。是的,这似乎是正确的。这就是为什么我不确定可能导致错误的原因。
-
您回复了我的评论,但没有编辑您的问题。请允许我重复一遍:请提供minimal reproducible example。
标签: c++ game-engine unreal-engine4 unreal-gameplay-ability-system