Hi guys)) I’m working on my project with some help from book “Learning C++ by creating games in unreal engine 4”. Book was written for older versions of engine and right now I have a problem with BotCharacter.cpp
the error is
C2248 ACharacter::Mesh: can not address the private member, declared in the class "ACharacter"
#include "Viking_Test.h"
#include "MeleeWeapon.h"
#include "BotCharacter.h"
#include "Viking_TestCharacter.h"
#include "Engine/SkeletalMeshSocket.h"
void ABotCharacter::PostInitializeComponents()
{
Super::PostInitializeComponents();
if (BPMeleeWeapon)
{
MeleeWeapon = GetWorld()->SpawnActor<AMeleeWeapon>(
BPMeleeWeapon, FVector(), FRotator());
if (MeleeWeapon)
{
const USkeletalMeshSocket* socket = Mesh -> GetSocketByName(
"RightHandSocket"); // Here error with mesh
socket->AttachActor(MeleeWeapon, Mesh);// and here too
}
}
}
botCharacter.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Character.h"
#include "BotCharacter.generated.h"
UCLASS()
class VIKING_TEST_API ABotCharacter : public ACharacter
{
GENERATED_BODY()
public:
ABotCharacter(const FObjectInitializer& ObjectInitializer);
virtual void BeginPlay() override;
virtual void Tick( float DeltaSeconds ) override;
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BotProperties)
float Speed;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BotProperties)
float HitPoints;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BotProperties)
int32 Experience;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BotProperties)
UClass* BPLoot;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BotProperties)
float BaseAttackDamage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BotProperties)
float AttackTimeout;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BotProperties)
float TimeSinceLastStrike;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BotProperties)
USphereComponent* SightSphere;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BotProperties)
USphereComponent* AttackRangeSphere;
inline bool isInSightRange(float d)
{
return d < SightSphere->GetScaledSphereRadius();
}
inline bool isInAttackRange(float d)
{
return d < AttackRangeSphere->GetScaledSphereRadius();
}
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MonsterProperties)
UClass* BPMeleeWeapon;
AActor* MeleeWeapon;
virtual void PostInitializeComponents() override;
};
meleeWeapon.p
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Actor.h"
#include "MeleeWeapon.generated.h"
UCLASS()
class VIKING_TEST_API AMeleeWeapon : public AActor
{
GENERATED_BODY()
public:
AMeleeWeapon(const FObjectInitializer& ObjectInitializer);
virtual void BeginPlay() override;
virtual void Tick( float DeltaSeconds ) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MeleeWeapon)
float AttackDamage;
TArray<AActor*> ThingsHit;
bool Swinging;
class ABotCharacter *WeaponHolder;
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category =
MeleeWeapon)
UBoxComponent* ProxBox;
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category =
MeleeWeapon)
UStaticMeshComponent* Mesh;
UFUNCTION(BlueprintNativeEvent, Category = Collision)
void Prox(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32
OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult);
void Swing();
void Rest();
};