Working with custom C++ code

Hello everyone, I am an experienced developer that just moved from Unity3D to Unreal Engine.

I have done basics tutorials, but I need some help to how to structure my code as I found no good tutorials or answers in this forum about the topic.

The structure I want to have is the following:

Logic:Pure C++ static classes and functions that drive all the logic.
Controller: C++ classes that will react on input/network and send events to the logic.
Model: Pure C++ classes/structs that keeps the application persistent data.
View: Contains C++ Classes and Unreal blueprients/actors that will display everything the player can see.

As you notice, the only part where I want to be dependent on Unreal Engine is the view, and maybe to some extent in the controller (for keyboard/mouse input).

However, I stumbled upon some serious problems, for example when I create a blank C++ file it won’t even show up in the editor, even if I add the UCLASS macro.
I am just wondering if anyone with experience can tell me how they deal with custom C++ code in their projects.

I don’t have much to say when it comes to your structure but if you add a C++ / Header file to the project, that is not from the editor feature of “add new class”, you can right click your .uproject and “Generate visual studio project files”. This should run through any of the code files added and then add them to the project.

Sounds like you could do with doing a few tutorials, as the questions you ask will be answered by example: Look at the Geting Started with C++ sticky for lots of ideas on where to go next.

Also note that implemeting a MVC or MVVM model withing UE4 would be going against the grain and you’d fight with the UE4 implementations every step along the way. Unlike in Unity3D, a UE4 project is not a blank slate. You have the entire gameplay framework right off the bat, and it doesn’t lend itself well to something like you’re trying to do. Good luck either way though!

Thank you for this neat tip, I will try it out.

There are existing frameworks in the engine that will make your life much much easier if you stick to them, instead of shoe-horning in design patterns from web dev. There is a reason you don’t see professional game developers talking about MVC/MVVM etc.

Learn the engine, don’t fight it.

Thank you for your feedback, but I have been using MVC and similar archietectures for many other things than web development in the past, also I been using it successfully in Unity3D. Concepts are similar but instead of my model being a database it is json structures. Maybe something is different with Unreal Engine, but I don’t see why it should be.

Yes I have noticed this too, specially in game engines, usually I do a bit if “cheating” to make the MVC structure useful, but other than that, the architecture have been working fine for me in the past. Maybe Unreal is different as you say, I think I will find out soon enough.

Thanks for the feedback, as an experienced developer, it is kind frustrating to have to through large amounts of tutorials which 50% is very basic C++ stuff I already know, I was hoping to find some sort of tutorial for advanced C++ users that would save me some time, but I suppose I just have to bite the sour apple and start doing all the tutorials. I might even learn a new thing or two :slight_smile:

Design patterns are tools to solve problems. If your problem is that you need a starting framework to build a game in UnrealEngine, then the solution is to learn the Gameplay Framework.

You’ll find it much better suited to building things in Unreal, and that there’s a fair bit of commonality.