#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 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.
Your semicolon needs to be at the end of the class:
#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.
}; <---Here
I tried commented out the rest and focuses on the UPROPERTY
This is the Header file the cpp is pretty much empty
#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 compiler says “Missing variable type” and it will only happen if I add this line UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
What exactly does it mean and how can I add this variable type? I copy pasted the code from the tutorial. I have no idea why it doesn’t work on me.
alone. You need to add a variable. You outcommented the
TSubobjectPtr<class USphereComponent> ProxSphere;
If you add it again, the error will be gone.
UPROPERTY is a makro from epic that does several things. Important for you is, that UPROPERTY belongs to a variable
and you have not a single variable after it.
EVERY UPROPERTY needs its own variable.
Do this and it should work again:
#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.
};
Nope. To make the Class ready for blueprints you need to add properties to the UCLASS Makro.
For example “Blueprintable” and “BlueprintType”.
These both mean that you can create a BP of this class and also create variables of this class.
Use a normal pointer:
class USphereComponent* ProxSphere;
It is also not an error but a warning that Epic will change it in the next version, so that you can’t use it anymore.
At the moment you can still use it, but you should make sure to change it when the new Engine update is live.
No offense taken Exclusiv3. I am actually grateful that my post is not ignored since the question is very newbie. But I guess everyone have to start some where.
I am actually following a book “Learning C++ by creating games in UE4” it covers all basic C++ from declaring variable to inheritance. I’m not sure if it’s the macros or there’s more to learn but looking at the script from Unreal seems a little bit different and scary.
I’m going to read the documentation first. Thanks for the link.
As for the error I don’t think it’s a warning. The compiler says failed to compile and the icon is red. I will come back to the error later after I finished the document
Edit:
I got it working, thank you for the help.
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)
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)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "interact");
}
}
One more question. How to write the deconstructor?
I’m having some trouble getting the code to work. I’m using Unreal Engine 4.12.5. I have substituted “class USphereComponent* Sphere;” for “TSubobjectPtr<class USphereComponent> ProxSphere;” My code looks like this:
UCLASS()
class BASICCPP_API ANPC : public ACharacter
{
GENERATED_UCLASS_BODY()
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
class USphereComponent* Sphere;
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;
codingbug your necroing a dead forum post thats two years old now. It would have been better if you just made a new thread.
Saying that I can’t really see any errors with the code you posted.
please send us your Output log when you complie from Visual Studio