Getting very angry at Plugin Development

So I get the five following errors:


Error	1	error : The first include statement in source file 'E:\UE4 Projects\RandGenLib\Plugins\RandomNumberGeneratorsPlugin\Source\RandomNumberGeneratorsPlugin\Private\MersenneTwister\mt.cpp' is trying to include the file 'cassert' as the precompiled header, but that file could not be located in any of the module's include search paths.	E:\UE4 Projects\RandGenLib\Intermediate\ProjectFiles\EXEC	RandGenLib

Error	2	error MSB3075: The command ""E:\Epic Games\4.9\Engine\Build\BatchFiles\Rebuild.bat" RandGenLibEditor Win64 Development "E:\UE4 Projects\RandGenLib\RandGenLib.uproject" -rocket -waitmutex" exited with code 5. Please verify that you have sufficient rights to run this command.	C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets	43	5	RandGenLib

3	IntelliSense: explicit type is missing ('int' assumed)	e:\UE4 Projects\RandGenLib\Plugins\RandomNumberGeneratorsPlugin\Source\RandomNumberGeneratorsPlugin\Private\MersenneTwister.h	3	1	RandGenLib

4	IntelliSense: class "MersenneTwister" has no member "GenerateMersenneTwisterArray"	e:\UE4 Projects\RandGenLib\Plugins\RandomNumberGeneratorsPlugin\Source\RandomNumberGeneratorsPlugin\Private\RandomNumberGeneratorsPlugin.cpp	25	30	RandGenLib

5	IntelliSense: a value of type "int **" cannot be used to initialize an entity of type "const int"	e:\UE4 Projects\RandGenLib\Plugins\RandomNumberGeneratorsPlugin\Source\RandomNumberGeneratorsPlugin\Private\RandomNumberGeneratorsPlugin.cpp	27	16	RandGenLib

6	IntelliSense: expression must have a constant value	e:\UE4 Projects\RandGenLib\Plugins\RandomNumberGeneratorsPlugin\Source\RandomNumberGeneratorsPlugin\Private\RandomNumberGeneratorsPlugin.cpp	28	13	RandGenLib

7	IntelliSense: no instance of function template "ArrayCountHelper" matches the argument list
            argument types are: (<error-type>)	e:\UE4 Projects\RandGenLib\Plugins\RandomNumberGeneratorsPlugin\Source\RandomNumberGeneratorsPlugin\Private\RandomNumberGeneratorsPlugin.cpp	46	19	RandGenLib



My RandomNumberGeneratorsPluginPrivatePCH.h file:


// Some copyright should be here...
#pragma once

#include "../Public/RandomNumberGeneratorsPlugin.h"
#include "../Private/MersenneTwister.h"
#include "../Private/MersenneTwister/mt.h"
#include "UnrealTemplate.h"
#include <cassert>

My RandomNumberGeneratorsPlugin.cpp file:


// Some copyright should be here...

#include "../Private/RandomNumberGeneratorsPluginPrivatePCH.h"
#include "../Public/RandomNumberGeneratorsPlugin.h"



#define LOCTEXT_NAMESPACE "FRandomNumberGeneratorsPluginModule"

void FRandomNumberGeneratorsPluginModule::StartupModule()
{
	// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
	
	
}

void FRandomNumberGeneratorsPluginModule::ShutdownModule()
{
	// This function may be called during shutdown to clean up your module.  For modules that support dynamic reloading,
	// we call this function before unloading the module.
	
	
}

TArray<int> MersenneTwister::GenerateMersenneTwisterArray(int* NumberOfEntries)
{
	const int N = &NumberOfEntries;
	double ran[N];
	double mean = 0.0;

	// Initialize a Mersenne Twister
	MersenneTwister mt;

	// Take N draws from Uniform(0,1)
	for (int i = 0; i < N; i++) {
		ran* = mt.random();
	}

	// Calculate the mean
	for (int i = 0; i < N; i++) {
		mean += ran*;
	}
	mean /= N;

	TArray<int32> tArr;
	tArr.Append(ran, ARRAY_COUNT(ran));

	return tArr;
}



#undef LOCTEXT_NAMESPACE
	
IMPLEMENT_MODULE(FRandomNumberGeneratorsPluginModule, RandomNumberGeneratorsPlugin)

My MersenneTwister.h file:


#pragma once

UCLASS()
class MersenneTwister : public UBlueprintFunctionLibrary
{
	GENERATED_UCLASS_BODY()
	UFUNCTION(BlueprintPure, Category = "RandomNumberGeneratorsPlugin", meta = (FriendlyName = "Mersenne Twister", CompactNodeTitle = "->", Keywords = "Mersenne Twister RNG Random Number Generator Math"))
		static TArray<int> GenerateMersenneTwisterArray(int* NumberOfEntries);
};


Nothing? :c

Beyond my ability to solve I’m afraid. Be patient, someone good at C++ will wander along soon :slight_smile:

Actually, just a thought: take the <cassert> out of the PCH and put it back in your cpp file, but after the PCH include.

Not sure if I’m doing it right or not, but I put every header from my codebase that I’ve written into the PCH, then include it again in the actual CPP or header file. But I only put code I wrote into the PCH.

As I said, ignore the Intellisense errors. What often happens is that one thing goes wrong, and that problem causes several other errors to appear. The idea is to always solve from the top of the error list onwards - oftentimes, after fixing the first one, the rest disappear :slight_smile:

In regards to the first one - it’s saying that the first #include in your RandomNumberGeneratorsPlugin\Private\MersenneTwister\mt.cpp file isn’t the PrivatePCH. Every single .cpp file in your project has to start with an include to your PrivatePCH. If you don’t, it will try to include whatever you put instead as the PrivatePCH, which in this case is probably ‘cassert’ (based on the error, at least - I can’t see mt.cpp obviously).

If you can’t add <iostream> and other native headers there’s something wrong with your VS/C++ redist installation.
As said above, PrivatePCH must be the first header for every and all .cpp files that include or are included by your UClasses.
And, you use GENERATED_UCLASS_BODY macro, but you never define any ObjectInitializer for any of the UClasses you’ve paste code so far. If you don’t want to build initializer yourself, use GENERATED_BODY() instead.

Okay. I’ll try that out and return. I’m sure I’ll have other issues afterwards. Thanks so far guys.

I’ve now taken the entire project and zipped up. I hope someone can spot where I’m going wrong.
Last night I tried to add the PCH file to all my C++ and H files but when I put it in some, it works, when I put it in others it can’t open the file. Some times given it a path like “…/Private…” helps but other times nothing helps at all and I’m just left with frustration over why it can’t read a file that I give it direct pointers to.

http://www.filedropper.com/randgenlib

I don’t hope it’s too much trouble…I’d appreciate it a lot.

Hehe. So many things. Mostly easy to fix.

  1. So if your PCH file is in “/Private” and your code is in “/Private/MT”, then the path needs to use "#include “…/MyPCHfile.h”. The …/ tells it to look back a directory for it.

  2. A *.cs file is C#, not C++, so don’t include your PCH there. :slight_smile: This is a totally separate piece of code that tells the compiler how to build your project.

  3. Files not in your solution that still exist in the directory structure (such as mtex.cpp) also need the PCH and ARE included in your build regardless. If you don’t want them included, move them out of the actual directory or delete them. The structure of your solution/filters doesn’t really mean anything unfortunately, it still looks at the windows file structure 100% when it builds and what you have in your solution view is pretty much imaginary. For sanity’s sake I keep mine 1:1 the same, but the solution structure is only for display.

  4. Unreal classes need to start with U or A. U for UObjects, A for Actors. The filename should still be MersenneTwister.h, but the class should be UMersenneTwister. Anywhere UCLASS() appears, this rule applies.

  5. Int isn’t a class type that UE supports. I know, it surprised me too. Because Int is different on every platform, it forces you to use uint8 or uint32.

  6. This is very important in blueprint class header files: #include “MersenneTwister.generated.h” - The file doesn’t exist so intellisense won’t like it, but ignore that. The UBT creates this file for you. It should always be the LAST include.

  7. Your UE code examples that you use seem to be out of date. I fixed FriendlyName -> DisplayName.

It’s still not building, but I’m guessing if you start over you’ll have more luck. The remaining issues are syntax problems or stuff where you haven’t adhered to the UE framework correctly. Make sure you use the UE editor “New class” command in the File menu to create your template class files. This will make life a LOT easier since a lot of the red tape is just handled for you. Basically most of the problems wouldn’t have come up if you’d gone the Plugin Wizard and then Editor New Class route on a fresh project.

Here’s a copy with the changes I made so you can see how they should be done: https:///#!WNFVVS7Y!Eoq0Mz5R1axRQwKeOy5V-MiHQh5b5NSeWiRrOtBHN1k (You might have to go to solution properties and fix your include paths as I changed them to C:/ drive)

I would recommend making a github repo so you can invite people to fix things and you can see exactly what was changed.

Thank you a lot. I will have a look at it.

In regards to your “Use the Plugin Wizard” comment, I actually did and then did a 1:1 in the file system and the project view just like I was told, but it still ****ed it up. I hope this’ll fix a few things :slight_smile:

Yeah it was a LITTLE bit off. I added in all the missing files and moved the Plugins directory back to the top level like it should have been. Like I said though, it doesn’t matter too much, apart from making it much easier to debug.

Well I copy and pasted it over what I had and it seemed to replace it just fine but then when I press “Local Windows Debugger” instead of “Rebuild” (as someone mentioned earlier can cause problems) I get the following errors:


Error	1	error C2504: 'UBlueprintFunctionLibrary' : base class undefined	e:\ue4 projects\randgenlib\plugins\randomnumbergeneratorsplugin\source\randomnumbergeneratorsplugin\Private\MersenneTwister.h	8	1	RandGenLib
Error	2	error C2146: syntax error : missing ';' before identifier 'Super'	e:\ue4 projects\randgenlib\plugins\randomnumbergeneratorsplugin\source\randomnumbergeneratorsplugin\Private\MersenneTwister.h	9	1	RandGenLib
Error	3	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	e:\ue4 projects\randgenlib\plugins\randomnumbergeneratorsplugin\source\randomnumbergeneratorsplugin\Private\MersenneTwister.h	9	1	RandGenLib
Error	4	error C3668: 'UMersenneTwister::_getUObject' : method with override specifier 'override' did not override any base class methods	e:\ue4 projects\randgenlib\plugins\randomnumbergeneratorsplugin\source\randomnumbergeneratorsplugin\Private\MersenneTwister.h	9	1	RandGenLib
Error	5	error C2275: 'UByteProperty' : illegal use of this type as an expression	e:\ue4 projects\randgenlib\plugins\randomnumbergeneratorsplugin\source\randomnumbergeneratorsplugin\Private\MersenneTwister.h	9	1	RandGenLib
Error	6	error C2065: 'Z_Param_NumberOfEntries' : undeclared identifier	e:\ue4 projects\randgenlib\plugins\randomnumbergeneratorsplugin\source\randomnumbergeneratorsplugin\Private\MersenneTwister.h	9	1	RandGenLib
Error	7	error C3861: 'P_GET_PROPERTY': identifier not found	e:\ue4 projects\randgenlib\plugins\randomnumbergeneratorsplugin\source\randomnumbergeneratorsplugin\Private\MersenneTwister.h	9	1	RandGenLib
Error	8	error C2065: 'P_FINISH' : undeclared identifier	e:\ue4 projects\randgenlib\plugins\randomnumbergeneratorsplugin\source\randomnumbergeneratorsplugin\Private\MersenneTwister.h	9	1	RandGenLib
Error	9	error C2440: 'return' : cannot convert from 'UMersenneTwister *' to 'UObject *'	e:\ue4 projects\randgenlib\plugins\randomnumbergeneratorsplugin\source\randomnumbergeneratorsplugin\Private\MersenneTwister.h	9	1	RandGenLib
Error	10	error C2614: 'UMersenneTwister' : illegal member initialization: 'Super' is not a base or member	e:\ue4 projects\randgenlib\plugins\randomnumbergeneratorsplugin\source\randomnumbergeneratorsplugin\Private\MersenneTwister.h	9	1	RandGenLib
Error	11	error : Failed to produce item: E:\UE4 Projects\RandGenLib\Plugins\RandomNumberGeneratorsPlugin\Binaries\Win64\UE4Editor-RandomNumberGeneratorsPlugin-Win64-DebugGame.dll	E:\UE4 Projects\RandGenLib\Intermediate\ProjectFiles\ERROR	RandGenLib
Error	12	error MSB3073: The command ""E:\Epic Games\4.9\Engine\Build\BatchFiles\Build.bat" RandGenLibEditor Win64 DebugGame "E:\UE4 Projects\RandGenLib\RandGenLib.uproject" -rocket -waitmutex" exited with code -1.	C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets	38	5	RandGenLib
	13	IntelliSense: cannot open source file "MersenneTwister.generated.h"	e:\UE4 Projects\RandGenLib\Plugins\RandomNumberGeneratorsPlugin\Source\RandomNumberGeneratorsPlugin\Private\MersenneTwister.h	4	1	RandGenLib
	14	IntelliSense: explicit type is missing ('int' assumed)	e:\UE4 Projects\RandGenLib\Plugins\RandomNumberGeneratorsPlugin\Source\RandomNumberGeneratorsPlugin\Private\MersenneTwister.h	6	1	RandGenLib
	15	IntelliSense: expected a '{'	e:\UE4 Projects\RandGenLib\Plugins\RandomNumberGeneratorsPlugin\Source\RandomNumberGeneratorsPlugin\Private\MersenneTwister.h	7	1	RandGenLib
	16	IntelliSense: identifier "GENERATED_BODY" is undefined	e:\UE4 Projects\RandGenLib\Plugins\RandomNumberGeneratorsPlugin\Source\RandomNumberGeneratorsPlugin\Private\MersenneTwister.h	9	2	RandGenLib
	17	IntelliSense: expected a ';'	e:\UE4 Projects\RandGenLib\Plugins\RandomNumberGeneratorsPlugin\Source\RandomNumberGeneratorsPlugin\Private\MersenneTwister.h	10	2	RandGenLib


Even more errors than before. But different ones for the most part at least. So maybe it’s on to more of the right thing…?

The file it got the most qualms with looks like this:


#pragma once

#include "RandomNumberGeneratorsPluginPrivatePCH.h"
#include "MersenneTwister.generated.h"

UCLASS()
class UMersenneTwister : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	UFUNCTION(BlueprintPure, Category = "RandomNumberGeneratorsPlugin", meta = (DisplayName = "Mersenne Twister", CompactNodeTitle = "->", Keywords = "Mersenne Twister RNG Random Number Generator Math"))
	static TArray<uint8> GenerateMersenneTwisterArray(uint8 NumberOfEntries);
};


Those are the errors I had, which was the point at which I recommended you start over with the proper workflow. :slight_smile: It shouldn’t take more than a few minutes to set up a new project, create a new template class then load VS and add your external code. Now that you’ve seen how it SHOULD look, the generated code may be more familiar.

It’s almost easier to just give up and never touch UE4 C++ again…I guess I’ll try… =_=

This is just a speedbump. Give it a go. :slight_smile:

1 Like

I want to throw my computer out the window right now. I tried to make a new project, and I get:


An error occurred while trying to generate project files.

Running E:/Epic Games/4.9/Engine/Binaries/DotNET/UnrealBuildTool.exe  -projectfiles -project="E:/UE4 Projects/RNGPlugin/RNGPlugin.uproject" -game -rocket -progress
Discovering modules, targets and source code for game...
ERROR: Couldn't find module rules file for module 'Random Number Generator Library'.

Did it create a *.build.cs file for your project?

@Vipar - Just a guess, but you might need to go into the .uproject file (open it with a text editor) and find where your old plugin entry is and delete it.

I may be off base in terms of what’s going on, though.

No, it didn’t.
And now I can’t make any new C++ projects at all that actually generates .uproject files…

It’s kind of…I don’t know how to put it. But it should not be this hard to get started ._.

1 Like

No, it shouldn’t be that hard. I’ve been wondering for a while what’s up with your setup. Blow it all away and start over. Reinstall Visual Studio Express 2013 and UE 4.9.2. Make sure you clean all the settings out of %appdata%/Local/UnrealEngine as well.

You shouldn’t be making any changes directly in Visual Studio. Just right click your .uproject and select “Generate Project Files”. The source code for any plugin in your Plugins folder will be added to your solution.