c++game-engineunreal-engine4unreal-gameplay-ability-system

How to fix the UClass has no member "WeaponMesh" error?


Currently I have a class for my character like so:

.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;


};

Please note the Weapon type. The weapon is a custom blueprint class derived from a custom general class for my weapons that looks like this:

.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;

};

Now I have another class which will put a tracker into the sockets of my weapons skeletal mesh in order to track it's movement later on. I am trying to call on that mesh through that blueprint class like so:

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");
}

Note that my Weapon variable inside this class is of type USkeletalMeshComponent, which is the same as WeaponMesh inside the Weapon_Base class. But when I call on the mesh I get the error UClass has no member "WeaponMesh". How would I fix that?

Thank you for your help!


Solution

  • For anyone that will be look for future answers, I have found the answer. Essentially the problem was that I pointed towards the class and not the actor I spawned. So what I did was I added another variable called weapon pointer to the character and saved the weapon in there which I then used to call upon the mesh of exactly that weapon.