Download

Error: BlueprintReadOnly should not be used on privat

Hello people.
I’m studying C ++ in the Unreal Engine 4 environment, I encountered a problem of this kind - I show in the screenshot 1.jpg - Google Drive



UCLASS()
class LEARNUE4_API ANPC : public ACharacter
{
GENERATED_UCLASS_BODY()
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
TSubobjectPtr<class USphereComponent> ProxSphere;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
FString NpcMessage;
}


Here in this place is a mistake. And interestingly, in TSubobjectPtrDeprecated if write TSubobjectPtr, that to me writes that it already out of date and need write TSubobjectPtrDeprecated

Problem solved:



	GENERATED_BODY()
		UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision, meta = (AllowPrivateAccess = "true"))
		USphereComponent* ProxShape;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage, meta = (AllowPrivateAccess = "true"))
		FString NpcMessage;


This is because GENERATED_BODY makes everything underneath it private. Just add public to the header:



GENERATED_BODY()
public:
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision, meta = (AllowPrivateAccess = "true"))
	USphereComponent* ProxShape;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage, meta = (AllowPrivateAccess = "true"))
	FString NpcMessage;