The following is my code for NPC which is a sub-class of a chracter
UCLASS()
class GOLDENEGG_API ANPC : public ACharacter
{
GENERATED_UCLASS_BODY()
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
TSubobjectPtr<class USphereComponent> ProxSphere;
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.
}
The compiler returns missing ; on line 25 (which is after the closing bracket)
I’ve tried to simplify it and only adds UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision) But it still return an error.
I’ve tried that before and still have compiler error.
If I remove everything except UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision) it will return “Missing variable type”. Any idea what that might be?
Try to add a ; after your closing curly bracket of your ANPC class. I.e.:
UCLASS()
class GOLDENEGG_API ANPC : public ACharacter
{
GENERATED_UCLASS_BODY()
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
TSubobjectPtr<class USphereComponent> ProxSphere;
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.
};
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.
}
And the CPP file have nothing inside.
Can u tell me how to define the variable of the UPROPERTY? The book doesn’t seems to declare anything and it’s the complete code that was given in the text. I’m using 4.7 atm the tutorial using 4.5 build. I hope it doesn’t make any problem. Can you please tell me how to declare the variable to resolve this issue?
Sorry about that guys. I’ve forgot to pasted the new code.
This is the header file
#pragma once
#include "GameFramework/Character.h"
#include "NPC.generated.h"
/**
*
*/
UCLASS()
class GOLDENEGG_API ANPC : public ACharacter
{
GENERATED_UCLASS_BODY()
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
//TSubobjectPtr<class USphereComponent> ProxSphere;
//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.
};
The CPP file is empty.
I’m following a tutorial where I make a subclass out of character. And the above are the codes I need to paste on the header file. Strangely it didn’t work for me. Could you please which variable to declare?
I;m just trying to expose this class to the blue print I;'m not sure what to declare. Again thanks for the help. My compiler error is still the same as above “Missing variable type”
You are not declaring any variable anymore. Try something like this:
#pragma once
#include "GameFramework/Character.h"
#include "NPC.generated.h"
/**
*
*/
UCLASS()
class GOLDENEGG_API ANPC : public ACharacter
{
GENERATED_UCLASS_BODY()
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.
};
Hey Dratone I got it working. Thank you very much for your help.
I’m using 4.7 and TSubobjectPtr can no longer be used.
This is the final code for viewers. Bare the noobness I just started C++.
#pragma once
#include "GameFramework/Character.h"
#include "NPC.generated.h"
/**
*
*/
UCLASS()
class GOLDENEGG_API ANPC : public ACharacter
{
GENERATED_UCLASS_BODY()
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
USphereComponent* ProxSphere;
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.
};
Cpp file
// Fill out your copyright notice in the Description page of Project Settings.
#include "GoldenEgg.h"
#include "NPC.h"
ANPC::ANPC(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
//GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "interact");
}