Error in code. Compiler says Missing semi collum at the end of the line

What could possible be wrong?


#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.

How to properly write UPROPERTY?

You need to close your class with a semicolon man…have you even tried putting one there?

Yes, and I think I’ve mentioned it above. Sorry if im not being clear.

I tried placing semi column at the end of the line but I still get an error “Missing Variable Type”

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision) <<< Why does this particular line gives an error?

Thanks for the input

Which line did you put the semicolon? You’ll get this error if you put a semi colon after the UPROPERTY line:



UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision); <---- Wrong


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


Hey ULLS,

Thanks for the input again.

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.

You were already told on the AnswerHUB that you can’t leave


UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)

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.
};

Okay I think I get it now.

Does this line mean

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision)
TSubobjectPtr<class USphereComponent> ProxSphere;

Prox Sphere will be exposed to the blue print?

Now I see why I get the error. I am still confused with the concept.

I thought UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Collision) will expose the class for me which is what im trying to do.

reading the category part and USphere component makes more sense to me now.

Thank you very much.

P.S
I still got compiler error :((((.

“It says TSubobjectPtr is deprecated. Use pointer instead”

so I tried TSubobjectPtr<class USphereComponent> *ProxSphere; and compiler and is not happy . It says Inapropriate

Is there relation between this and the version? I’m using 4.7 the tutorial is using 4.5

Hi LoveTune, I would suggest reading this, it might give you some more information about properties.


TSubobjectPtr<class USphereComponent> *ProxSphere;

No, you really should read a bit in the docu about C++ :wink:
And maybe C++ in generell (just an advice, don’t want to offend you) :wink:

It means:


class USphereComponent *ProxSphere

And yes there is an relation, because many things have changed and back at 4.5 TSubobjectPtr wasn’t deprecated

Yes.

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 tried ANPC::~ANPC(){}

It doesn’t compile.

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;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = NPCMessage)
FString NpcMessage;

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;

};

Any help would be great! Thanks!

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

To be fair, the sheer number of macros involved in this engine can be absolutely maddening.