x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

 UCLASS(Blueprintable)
 class CPPCUSTOMCHARTEST_API GetHelloWorld
 {    
     GENERATED_BODY()
 public:
     UFUNCTION(BlueprintPure, meta = (DisplayName = "Print Hello", Keywords = "Hello World"), Category = Game)
         static FText returnText();
     GetHelloWorld();
 };
Product Version: UE 4.12
Tags:
more ▼

asked Jul 17 '16 at 02:47 PM in C++ Programming

avatar image

DEVOPLER GUY DUDE THING
33 4 4 6

avatar image Cloudy McStrife Jul 17 '16 at 09:48 PM

Hey :)

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.

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

Greetings Cloudy

avatar image DEVOPLER GUY DUDE THING Jul 17 '16 at 09:52 PM

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

avatar image Cloudy McStrife Jul 17 '16 at 09:55 PM

No Problem. I hope it works for you :)

avatar image DEVOPLER GUY DUDE THING Jul 17 '16 at 10:16 PM

It does not work still.

avatar image Cloudy McStrife Jul 17 '16 at 10:17 PM

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

avatar image DEVOPLER GUY DUDE THING Jul 17 '16 at 10:33 PM

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 ;
 {
     GENERATED_BODY()
 public:
     UHello();
     ~UHello();
 };
 



avatar image Cloudy McStrife Jul 18 '16 at 07:27 AM

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.

Greetings Cloudy

avatar image DEVOPLER GUY DUDE THING Jul 18 '16 at 06:38 PM

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

avatar image Cloudy McStrife Jul 18 '16 at 07:07 PM

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??

avatar image DEVOPLER GUY DUDE THING Jul 18 '16 at 07:35 PM

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.

avatar image Ovodus Jul 18 '16 at 07:18 PM

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.

avatar image Cloudy McStrife Jul 18 '16 at 07:25 PM

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

Greetings Cloudy

avatar image Ovodus Jul 18 '16 at 07:33 PM

Well, then read my answer I've just published. :)

avatar image Cloudy McStrife Jul 18 '16 at 08:47 PM

Yeah exactly the thing I recommended :D

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 :)

Good luck

Greetings Cloudy

avatar image Ovodus Jul 18 '16 at 09:18 PM

You are right. It's all important and your intentions are good. :)

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. :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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:

MyNewObject.h:

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #pragma once
 
 #include "Object.h"
 #include "MyNewObject.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class MYGAME_API UMyNewObject : public UObject
 {
     GENERATED_BODY()
 
 };
 

MyNewObject.cpp:

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "MyGame.h"
 #include "MyNewObject.h"
 

more ▼

answered Jul 18 '16 at 07:32 PM

avatar image

Ovodus
89 3 4 9

avatar image DEVOPLER GUY DUDE THING Jul 18 '16 at 08:09 PM

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

avatar image Ovodus Jul 18 '16 at 08:21 PM

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?

avatar image DEVOPLER GUY DUDE THING Jul 18 '16 at 08:21 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question