Getting errors by creating a actor class from ue4

Created a brand new project and it compiled fine. I added an actor class to my code and I’m getting errors now like “name followed by ‘::’ must be a class or namespace name” Haven’t changed the code or or anything, following along with the youtube tutorials. Any help is much appreciated.

I’m using UE 4.12 and VS 2015 Community Edition

What did you use to create class? VS?

Though unreal. Under File>New C++ Class>Actor

“name followed by ‘::’ must be a class or namespace name” means that, for whatever reason, VS doesn’t know about the APickup class you’ve defined.

Make sure you’ve got your “{MyGame}.h” include at the top of your .cpp file (where {MyGame} is the name of your game project include [is that what “CodingTest.h” is?]).

Can you post the contents of Pickup.h? There may be a formatting error there.

1 Like

I added the {MyGame}.h but getting “cannot open source file”
yes the name of the project is CodingTest

Here is Pickup.h

107717-2.png

If you already had “CodingTest.h” included in your .cpp then that was the “{MyGame}.h” file; I don’t mean to literally add “{MyGame}.h”, I’m using {MyGame} as a placeholder for whatever your game project is called.

Try deleting the “.vs”, “Binaries”, and “Intermediate” directories within your project folder (make sure Visual Studio isn’t open); and then regenerate the project files (Right-Click on your .uproject file, and select “Generate Visual Studio Project Files”.
When that’s done, open your project in Visual Studio, allow it to scan your project, and then when it’s ready try the build again.

It looks like Visual Studio isn’t finding the Pickup.h file, if forcing the project re-scan doesn’t help, can you post the directory structure that leads to your Pickup.h and Pickup.cpp files?

i.e.
“Project Directory/Source/Actors/Pickup.h”
“Project Directory/Source/Actors/Private/Pickup.cpp”

As a long shot, you could also try adding a call to the AActor constructor:

APickup::APickup()
    :
    AActor()
{
    PrimaryActorTick.bCanEverTick = true;

}

If you get errors from your build, please post the content of the Output tab so we can get a better idea of what’s going on.

I did delete the stuff and regenerated the project but still got the errors. I try adding the code and got more errors, idk if I just put it in wrong. Very new to codding in Unreal

Please post the contents of the Output tab after running your build, and post the directory structure and filenames for your Pickup.h and Pickup.cpp files.

Also, go ahead an post the contents of Pickup.h and Pickup.cpp so I can be sure where you’re at with the code.

It also might be helpful to see a screengrab of your solution explorer in Visual Studio expanded to your Pickup.h and Pickup.cpp files.

Sorry, the photo must have not uploaded. Photo Posted of error list and .cpp and .h

Output:
1>------ Build started: Project: UE4, Configuration: BuiltWithUnrealBuildTool Win32 ------
2>------ Build started: Project: CodingTest, Configuration: DebugGame_Editor x64 ------
2> Performing 2 actions (4 in parallel)
2> Pickup.cpp
2>C:\Users\Name\Documents\Unreal Projects\CodingTest\Source\CodingTest\Private\Pickup.cpp(15): error C2447: ‘{’: missing function header (old-style formal list?)
2>ERROR : UBT error : Failed to produce item: C:\Users\Name\Documents\Unreal Projects\CodingTest\Binaries\Win64\UE4Editor-CodingTest-Win64-DebugGame.pdb
2> Total build time: 0.96 seconds
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(41,5): error MSB3075: The command ““C:\Program Files (x86)\Epic Games\4.12\Engine\Build\BatchFiles\Build.bat” CodingTestEditor Win64 DebugGame “C:\Users\Name\Documents\Unreal Projects\CodingTest\CodingTest.uproject” -waitmutex” exited with code 5. Please verify that you have sufficient rights to run this command.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

107760-4.png

You’ve doubled up the body of your constructor, delete lines 11 - 14 in Pickup.cpp

Try your build again and see what happens.

Also, you’re posting the “Errors” list from Visual Studio, that’s an unreliable tool with UE4.
If you look at the bottom of that window you’ll see an “Output” tab, post the messages from that instead.

Deleted 11-14 and rebuild the code and build the code and it works now. It seems I just need to add a line of code. Thank you so much for the help, been waiting a long time work out a bunch of problems between UE4 and VS. Thank you for your time and have a nice day.

I betcha the fix was regenerating the project files. That’s often a necessary step after adding new files.

Glad it’s working for you.