Don't work added property

Hello, I study the engine based on the book by William Sheriff, and is now focused on creating NPC. He brought the example code to show the new settings:

UCLASS()
    class GOLDENEGG_API ANPC : public ACharacter
    {
    GENERATED_UCLASS_BODY()
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
    TSubobjectPtr<class USphereComponent> ProxSphere;
    // This is the NPC's message that he has to tell us.
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
    FString NpcMessage;
    // When you create a blueprint from this class, you want to be
    // able to edit that message in blueprints,
    // that's why we have the EditAnywhere and BlueprintReadWrite
    // properties.
    }

Of course it did not work for the new version, and I had to rewrite it (using code from other resources).

UCLASS()
class GOLDENEGG_API ANPC : public ACharacter
{
	GENERATED_BODY()
public:		
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
		USphereComponent* ProxSphere;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
		FString NpcMessage;

	// Sets default values for this character's properties
	ANPC();
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;
	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;	
};

Then I Recompile this class in Blueprint, but the details do not have fields with my variables. Where is the mistake?

Did you successfully compile your C++ code?

I solved the problem, It should have been a piece of code:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
         USphereComponent* ProxSphere;
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
         FString NpcMessage;

Insert in the bottom, so it turned out:

UCLASS()
class GOLDENEGG_API ANPC : public ACharacter
{
	GENERATED_BODY()
		

public:
	
	// Sets default values for this character's properties
	ANPC();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
		USphereComponent* ProxSphere;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
		FString NpcMessage;

};

Code don’t compile if i I put a UPROPERTY in private.I wrote that I had not allowed

Add “public:” before GENERATED_BODY()

UCLASS()
class GOLDENEGG_API ANPC1 : public ACharacter
{
public:
	GENERATED_BODY()
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
		class USphereComponent* ProxSphere;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
		FString NpcMessage;

Still getting errors.

I tried to add "public: " modificator before GENERATED_BODY(). And it works fine