My c++ code should work, but UCLASS and class is throwing errors that can't be fixed

I get the error: “This declaration has no storage class or type specifier” in regards to the word UCLASS, and “class” returns “Expected a ;” I have retried this at least 10 times, to NO avail. What is wrong?

	UFUNCTION(BlueprintPure, meta = (DisplayName = "Print Hello", Keywords = "Hello World"), Category = Game)
		static FText returnText();

THANK YOU. SO. MUCH. (Will test in a second)

Hey :slight_smile:

GetHelloWorld has to derive at least from UObject to use UClass.
If should be an Actor (An Actual “Being” in the Scene) it has to derive from AActor

so adding:

: public UObject //or.. :public AActor

after GetHelloWorld should do the trick.

If it derives from UObject it has to have the prefix U (UGetHelloWorld)
From AActor it has to have the prefic A (AGetHelloWorld)


No Problem.
I hope it works for you :slight_smile:

It does not work still.

I tried in a different file (because I got rid of the other one, thinking it was just a fluke) this is what I still have:

// Fill out your copyright notice in the Description page of Project Settings.


UCLASS(Blueprintable) //This declaration has no storage class or type specifier 
class TESTFORCODE_API UHello : public UObject //Expected a ;

Can you show me you code?
The whole .h file if possible :slight_smile:

You still have to include the Hello.generated.h file

Just add

#include "Hello.generated.h"

In your Hello.cpp
You have to:

#include "testforcode.h"

You probably have to generate a new Visual Studio Solution file by
right Clicking on your .uproject file and click on “Generated Visual Studio Project Files”

After this you can build your Project again

Another question:
Didn’t you use the Class Wizard from Unreal Editor?
He generates all the dependencies one Class should have.


No matter how many times I generate the project files by right clicking on the .uproject, I never get the .generated.h files.

Then try to do the following:

Delete the solution file. Then go to you Binaries Folder and delete all files and directories in there (In mine is Win64 because I built my Project for that).

Then try to generate the solution files again.

Which errors do you get at the moment when trying to build??

Use Build->Rebuild Solution in VS. Cause generated files being actually generated during build process. I’d also recommend you to close UE Editor before rebuilding.

Your class should deriver from AActor or UObject. Also it should include some generated headers and so on.
It’s kind a boring task to explain every aspect here, so the best solution for you should be making new class from Unreal Editor:

  1. Start Unreal Editor.
  2. In Content Browser open C++ Classes.
  3. Choose folder you want your newly created class to be in.
  4. Right click on free space and choose “New C++ Class…”
  5. In a Choose Parent Class window click on checkbox in right top corner called “Show All Classes”
  6. Type “UObject” in search field to be sure you are right. Or just:
  7. Select Object in search results and click Next button.
  8. Name your class and check desired location.

As a result, you’ll get already compiled, correctly written class.

Like this one:


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Object.h"
#include "MyNewObject.generated.h"

class MYGAME_API UMyNewObject : public UObject



// Fill out your copyright notice in the Description page of Project Settings.

#include "MyGame.h"
#include "MyNewObject.h"

Well, then read my answer I’ve just published. :slight_smile:

Unfortunately rebuilding does not help everytime.
I often had issues where the only way I could go on, where the steps I descriped above.


Error MSB3073 The command ““C:\Program Files (x86)\Epic Games\4.12\Engine\Build\BatchFiles\Rebuild.bat” MyProject5Editor Win64 Development “C:\Users\matth\OneDrive\Documents\Unreal Projects\MyProject5\MyProject5.uproject” -waitmutex” exited with code -1.

It’s a Visual Studio error message. VS needs time to understand, whether there is a problem or not. Question is, what error being thrown at compile time in Output window?

I did EXACTLY what you said, and it still throws a “Can’t read source file” error for the .generated.h file it makes.

Actually, after numerous attempts, it seems to have accepted it, and hadn’t due to the project I had used.

Yeah exactly the thing I recommended :smiley:

But I wanted to explain all dependencies one class should have.
When I first used Unreal there were many Errors and I didn’t know why, until I realized that the Naming Conventions etc. where essentially. (F before struct name, U before Object and/or Components A before Actor)
Also other things like .generated.h and so on are things you have to know when using Unreal Engine, because the Compiler is not a help, when trying to find the error.

So I tried to show him all the things he has to be careful at.

But fortunately the problem is solved now :slight_smile:

Good luck


You are right. It’s all important and your intentions are good. :slight_smile:

If he’d like to get knowledge about all this aspects, he would have read Programming Guide section in Unreal Engine’s docs. But all he needs - is shortcut to God. And know what? That is normal, we are all humans. :slight_smile: