Best way to put a neural network into Unreal? (Plus a building question)

So I’m doing a simulation for a robot that’ll be using the NEAT algorithim. I’ve been trying to think of ways to incorporate it into the program, but I really cant think of anything besides putting it in a custom player character. Even though I know C++ I sadly don’t know unreal c++ yet, or even how to set the project to c++17 (which is extremely necessary for the code, and yes I looked it up I’m going to be trying the methods they gave). Any ideas?

Edit: got stuck here

“ Now build your game project with the build settings set to:

PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
CppStandard = CppStandardVersion.Latest;

3 Likes

Bumps

Bump again. Can someone just answer the question about custom building?

Unreal C++ is Normal C++ with more flexibility.
For your task use the character and micro devices to generate links to control your robot device.

For adding support for C++ 17:
In your project Source folder find the “.Build.cs>” file. e.g. “Escape.Build.cs” and add the following line to the constructor function that is already there:

CppStandard = CppStandardVersion.Cpp17;

restart and rebuild required.
hope it helps, cheers!

What kind of simulation? What does the robot do? what kind of API do you need? Is this a machine learning case or do you want to test your existing bot through a virtual environment? So many questions!

UE is a game / media engine. Any kind of mechanical sim, material stress test, physics sim is going to suck. UE is good at producing modern graphics which you can use for machine learning.

Again depends on what you are trying to do, in detail. The existing code for “Characters” in UE is the ACharacter class which moves around using a movement component. This component comes with tons of game-ready code like multiple modes of navigation, pathfinding and animation system out of the box. But depending on what you need for your robot half of it might be irrelevant or undesired. Need more info.

I don’t know what kind of project it is, hobby, school, work etc. but I’d look around for info on what other people are using. My first thought is Boston Dynamics :smile: I love bots.

using System.IO;
using UnrealBuildTool;

public class YourModule : ModuleRules {
	public YourModule(ReadOnlyTargetRules Target) : base(Target) {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
        CppStandard = CppStandardVersion.Latest;

		IncludeSubDirectoriesRecursive(ModuleDirectory + "\\Private", true);
		IncludeSubDirectoriesRecursive(ModuleDirectory + "\\Public", false);

		PrivateDependencyModuleNames.AddRange(new string[] {
			"Core",
			"CoreUObject",
			"AnythingElseYouNeed"
		});

		PublicDependencyModuleNames.AddRange(new string[] {

		});
	}

	private void IncludeSubDirectoriesRecursive(string DirectoryPathToSearch, bool bIsPrivate) {
		foreach (string DirectoryPath in Directory.GetDirectories(DirectoryPathToSearch)) {
			if (bIsPrivate) {
				PrivateIncludePaths.Add(DirectoryPath);
			}
			else {
				PublicIncludePaths.Add(DirectoryPath);
			}
			IncludeSubDirectoriesRecursive(DirectoryPath, bIsPrivate);
		}
	}
}


Basically, this is the vex spin up game. https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwj5n-aChcn4AhXIDkQIHe2aBkMQwqsBegQIAxAB&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DwIZgvVDZc2Y&usg=AOvVaw3tQYi4XTa4ulT8v3nJFHmj

I’m going to keep it as simple as possible, and since our robot will automatically aim towards the goal (since it’s a turret) I don’t need to worry about the robot rotating, and I’m certainly not learning physics, as I’m making code for the robot to shoot from anywhere. In other words, I just need the Unreal robot character to move on a 2d plane (obviously not using paper 2d, just normal 3D space), know x and y where it is on the field (there’s a 3D model for it, I can handle all that) and be able to detect where all the discs are. I can handle the inputs, my main issue was simply how to do a custom build. And yes, this is machine learning, look up MarI/O on YouTube if you’re interested in my specific method. Once the robot trains itself enough and it does well in unreal, I should hopefully be able to copy the genome of the network over to my robot, and then it can run and do it’s thing.

I did add that (as far as I can remember, it was two weeks ago) and I also rebuilt the game from the build button. However, is this the button I press, or is there something else I need to do besides just press “Build”?

1 Like

to build the code exit the editor (completely) else you can corrupt things with the hot reload / live feature. Then go into visual studio and hit Build. code will compile… Then restart the UE editor to use the new code. Inside the editor you also have a Build button but this does other things. There is also a Compile button in there which compiles blueprints only. So you don’t have to do anything else in the editor if you only write c++ and build in VS.

Alright. I sadly cannot try this today, but I will try tomorrow. Thank you

Are you rolling your own version of NEAT or using an external library?

If you do roll your own I would highly suggest making all major classes UOBJECTS so they can be inspected, debugged, and parameters changed in Unreal Editor easily.

Other potential issues if you are importing a 3rd party C++ library into an Unreal project. Any Winsock stuff will require some special header file workarounds. Been a few years since I tried, but last I checked any C++ CLR stuff simply won’t work at all with an Unreal project.

I’m using this library: GitHub - BiagioFesta/EvolutionNet: NEAT (NeuroEvolution of Augmentic Topologies) C++ Library Algorithm Implementation

I added many, MANY comments as it was severely lacking, but am still very confused on how to create input and output nodes. That’s unrelated though (If you would happen to know the answer I’ll take it in a heartbeat though), since it is all C++17 standard and works for the robot (VEXOS is very annoying to add libraries into, sometimes even namespaces don’t work) it SHOULD work for unreal.

So I got covid ha ha and that sucked, but lemme ask now that I’m better, which file do I have to recompile? Every one I go into says attatch blah blah blah at the top instead of local windows debugger like usual.

If you make a change to a c++ file in your project you recompile the entire project in VS.

This requires an explanation, I don’t know what you are doing or where you are reading this. Attaching a debugger to a process is something else than recompiling and you can just attach VS to the UE process to debug things.