Not finding sword mesh for AI

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

You just need to use GetMesh() instead of directly accessing “Mesh”.

The Mesh variable was made private in a recent release meaning you cannot access it directly anymore.

It is a common coding pattern to use accessors (GetMyVariable() / SetMyVariable(…)) to provide controlled access to private variables so that users of the class don’t accidentally change the pointer reference (for example) or mess things up in other ways.

Oh thank you))
but i wonder how to add the sword to my bot, because it didn’t worked

It’s hard to say why the sword wasn’t added without looking at your setup, there could be a number of different reasons.

For example, did you remember to setup the socket “RightHandSocket” which your code is using on the skeleton of your character?

Second, is BPMeleeWeapon pointing to a valid value and if it is does it have a proper mesh setup for the sword?

I recommend slowly working your way through every single aspect of the setup to verify if you’ve missed something. Try debugging the code by putting a breakpoint in PostInitializeComponents and observe what happens.