C++ programming without Unreal Editor

I’m an Unreal beginner, so correct me if I’m wrong, but is it possible to create Unreal C++ application without Unreal Editor ?
As far as I can see, we can write C++ code (actors, custom classes, etc.) which is called from Unreal.
Is it possible to write the full application from main() function ?
I couldn’t find any example.

No. Unreal Engine is too complicated, and has it’s own unique things that make that undoable.

What “things” make it impossible? Could You mention at least one?

I think it should be possible. :slight_smile:

If I am not entirely mistaken you can try to use the SlateViewer as a reference.

In fact it is not necessary to drag all of UE4 into a Slate Application. So you should be fine creating like an LOB application using that :slight_smile:

Perhaps someone from Epic can clarify what approach would be best here :wink:

You can’t create materials in C++. Importing meshes to use as assets can’t be accomplished in C++ (easily. I’m sure it can be done but why do months of C++ work when 5 minutes in the editor will accomplish the same goal?). Also, not entirely certain you can set up animation blends in C++.

It would also be quite difficult to place objects in a scene. Sure you can do it, but who wants to compile/link/run just to ensure you placed a chair close enough to a table? That’s the kind of stuff the editor is for.

Just a quick note: there are things that are much, much, much easier to do in blueprints than in c++, especially dealing with objects at runtime.

What are you trying to do specifically?

Like rubenst said, it’s perfectly possible to create a Slate application that doesn’t depend on the engine at all. Take a look at the UnrealFrontend project for a good example. Of course, this is a rather clumsy way of making GUI applications (to put it mildly), and you’d probably want to look at a more suitable toolkit like Qt.

On the other hand, if you are looking to create something that uses the actual engine, creating an application.cpp with a main() isn’t really going to cut it. Yes, it’s technically possible, but impractical to the extreme. To see why, have a look at the build system documentation to see how the engine is built. As you can see the build system alone is extremely complex. That’s not just because someone thought it would be fun to make it that way, it’s because the engine is a huge piece of software with tens (hundreds?) of interconnected dependencies that needs to be able to run on many completely different architectures. In short, creating “the application” has already been done for you, and it has been done by a very large team of skilled developers that worked on it for years. If you think you can do a better job, well… good luck. Whatever functionality you are missing from the engine (or want removed) can be attained much more easily by modifying the existing editor. Some options:

  1. Create a runtime plugin.
  2. Create an editor module.
  3. Customise the source code yourself. It’s all there! This is still orders of magnitude less work than starting from scratch.

In short, creating “the application” has already been done for you, and it has been done by a very large team of skilled developers that worked on it for years. If you think you can do a better job, well… good luck. Whatever functionality you are missing from the engine (or want removed) can be attained much more easily by modifying the existing editor.

[/QUOTE]

No, I did not mean to be smarter than UE developers, I just wanted to have more control over the project, perhaps easier portability between platforms (Windows and Linux), etc.
No problem, I will use application generated by Editor.
However, there is one issue: I would like to have 1 central object in my application with method allowing easy control of the whole lifecycle: some init() method at the beginning, some tick()/work() method called periodically to conduct some non-unreal related activities, some destroy() method called at the end to clean everything up, and to create and destroy actors programatically inside.
Is there some dedicated object in UE for this purpose, or is it necessary to create some dedicated Actor without visual representation ?
I am still a UE beginner, thanks for any help.

Thanks,

I don’t know enough about the engine internals to answer this completely, but here are some functions you may want to take a look at (taking Windows as an example):

  1. WinMain() in Runtime/Launch/Windows/Private/LaunchWindows.cpp: this is where all the hairy platform specific stuff happens: environment setup, crash handling, misc. other workarounds and hacks. All platforms have some equivalent of this. It’s a good bet you don’t want to touch anything here.
  2. LaunchEngineLoop::PreInit(): command line parsing, log initialisation, which game are we loading, are we running a client or a server, do we use cooked assets or not, where are the assets located, which commandlets do we run, load startup modules, threading setup, and so on. This is a pretty important function to take a look at if you’re making modifications to the engine.
  3. FEngineLoop::Init(): called directly after PreInit(). This function is not so spectacular and its main purpose is to determine whether the exe is a game or an editor.
  4. FEngineLoop::Tick(): this is your tick function. You can take a look at it yourself to see what’s happening there, but what I would recommend to do instead is make a new C++ project in UnrealEd and override Tick() in your game mode. Then set a breakpoint there (remember to compile in debug mode), launch with the debugger attached and check the call stack at the breakpoint. This will give you all the info about how the tick chain propagates and what would be a good place for you to make your changes. The reason I recommend this is that the further away you go from the game code, the more knowledge of engine internals you need to have to make sure your changes are correct. Furthermore, modifying lots of internal engine code will give you a headache when a new engine version comes out, because there is no API compatibility guarantee and the number of ways things can break is endless.

So yes, I would say stick with an actor (AGameMode is one) and use that actor’s Tick() or if needed one of the engine functions that calls this tick. The engine is pretty flexible, and you barely need to have a ‘game’ for this to work. Depending on your needs you can also compile in server mode, that way you don’t even need a GUI to run your program (but watch out for side effects from doing this, best to grep for UE_SERVER to understand the implications and modify as necessary).

I’m curious. Do you have an example?

Why on earth would you want to exclude the editor steps? Is there any point in reinventing that entire toolchain just to not use the editor at some point?

Thanks for explanation. It seems it does not make sense to try to write code from scratch.
For lifecycle issue, I will use static, invisible actor as a top of my framework and use its methods to control the application.
I create client application which connects to external (not UE) server and serves mainly as visualization endpoint, so I don’t think I need server mode.
And that’s the reason of my questions: for me UE is only one of the several application components.

I think I answered this above - I’m not going to reinvent the entire toolchain, rather to have more control over the entire application, which contains much more than UE.

I don’t think your method is appropriate. Even if UE is just one piece in your application. Write your application program and have it launch your UE game then, but make the Unreal Game as normal. You will probably just give yourself a headache trying to rewire the framework and there’s no need. You can stick the game window on your applications canvas if you want. You will need to build an Interface between your host application and Unreal, you can do that with a C++ dll.

I have done a similar thing with a Windows WPF application as host and a flight simulator that’s viewport was put on the windows canvas.

You need to understand Application Space and write your own code that serializes objects across it, as the two programs will not share memory space. This stuff isn’t trivial and you should probably avoid it if you can change the design, such as having a separate web Interface for your application and the UE4 client communicates with your webserver as well. That would be much simpler than having one application contain another as a component.

Could you please tell a bit more how it was implemented ? I’m also very interested how to embed Unreal visualization viewport in custom GUI application, but preferably Qt, not Windows WPF.

@rkow98823

WPF windows applications have a canvas, I just put the viewport of the flightsim on the Canvas, so to the user it looked like it was one program. But, it was really 2 completely separate programs running that passed data back and forth. I don’t suggest you do that, a lot of work for minimal gain. It would be easier for you to make a webserver that your UE4 game client communicates with, and yoru other applications communicate with.

@rkow98823

I am also new to Unreal Engine and I have a similar goal like you.

I am eager to know if you were you able to continue with your idea? I want to do the same as you, open Unreal game canvas in a space inside my program in Qt.

I see a lot of people here poo pooing the idea of building the engine outside of the editor, even comparing the time it would take to do that with the time it takes to build a scene in the editor. Obviously, the people who asked that question have different goals in mind than writing a game, we for example are trying to use Unreal Engine as a previz engine inside a different tool, thus we need simply to have the engine render the frames to a custom image object without taking control of the main execution thread in the application. Those are valid goals and despite many people in the community don’t seeing immediately its purpose, nevertheless it is a useful thing to discuss in here. I too am interested in the path to compiling just the engine part of Unreal as a library to be compiled as part of a different system(running in the same process).

In that case you should probably use the editor just like the pros do. It would be extremely counter productive not to.

Hi , thanks for your approach and knowledge.

Could you develop further the webserver idea? Why could it be better than a simple IPC approach?

This approach from 2016 keeps being the best option today?