C++ NPC/Textbook Syntax Help

Hi there! I’m a student that is currently taking Video Game Design and the textbook we are currently using is a bit outdated. I’m halfway through chapter 8 and I’m at a point where we are supposed to make NPC characters. The code I’m supposed to use in an NPC class is

UCLASS()

class GOLDENEGG_API ANPC : public ACharacter
   {

GENERATED_UCLASS_BODY()

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category =
     Collision)

TSubobjectPtr ProxSphere;
     // This is the NPC's message that he has to tell us.

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
     NPCMessage)

FString NpcMessage;
     
} 

However when I input this code (Yes I changed the class name in my code) I get a compiler error saying that BlueprintReadWrite shouldn’t be used in a private way yet I’m 50% sure the class is public, I followed the textbook word for word. If you guys know of any syntax issues with the outdated textbook pls help.

Hey DinosaurDan,

I am pretty sure the class macro GENERATED_UCLASS_BODY changed its privacy at some point in the last year or so.

All you should need to do is update the code to:

 UCLASS() 
 class GOLDENEGG_API ANPC : public ACharacter
 { 
	GENERATED_UCLASS_BODY()
 
 public:
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category =
	Collision)
 
	TSubobjectPtr ProxSphere;
    
	// This is the NPC's message that he has to tell us.
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
	FString NpcMessage;      
 }

Thank you for the reply! Once I added the “public:” section in the code UPROPERTY stopped giving me errors, buuuuut I got a whole new mess of things that I can’t quite understand.

Yeah, that. The most I can get from that is the ProxSphere (which I believe to be a proximity sphere) can’t be made from whatever reason. I’d love if you could give me a bit of help or a tip on this part as well.

In your logs:

"TSubobjectPtr is deprecated and should no longer be used. Please use pointers instead."

I see, I appear to have missed that. Thanks! Now I hope you don’t mind but I’ve moved onto the next chapter which involved HUD’s however whenever I compile the code given:

void AMyHUD::DrawHUD()
{
    Super::DrawHUD();
    
    DrawLine( 200, 300, 400, 500, FLinearColor::Blue);
    DrawText("Greetings from Unreal!", FVector2D( 0, 0 ), hudFont,
    FVector2D( 1, 1 ), FColor::White);        
}

It gives me an error saying there is no conversion from FLinearColor to FVector2D and I can’t seem to find how to convert them as the textbook says to on google.

Hey again,

It appears the book you are using is quite a bit out of date. The function signature for DrawText has changed. You should be able to use the following update:

        DrawText("Greetings from Unreal!", FLinearColor( 1.f, 1.f, 0, 1.f ), 0, 0, hudFont, 1.f, false );        

DrawText( ) Documentation