Download

Design patterns, Unreal engine and breaking the ice. (n00b)

I have been coding for 8 years now, mainly for applications… During this time I have learnt some code design patterns that allow me to maintain a separation of concerns, practice loose coupling of components etc etc… I do not know a wide range of patterns used for gaming although i’m sure a lot of them I use without knowing it.

My problem with breaking the ice on a new framework is to know how much I can push it to make myself feel comfortable in the code.

I have a few questions that may be very hard to understand and comprehend considering i’m trying to fit my application knowledge into a game (which may or may not work… so thanks for your hard work and time in trying to answer my questions):

  1. I love MVC and MVVM for building web applications and desktop applications. dividing the code up into these very different roles helps prevent code duplication and removes some of the complexities of large applications.
  • What would the model section of the unreal engine be called or what components can be identified as model parts, and do I have to write the models in such a way for the unreal engine ui to understand what’s going on. For example, in my applications I set up models called repositories, they deal with interacting with databases and retrieve strong typed objects… this allows me to re-use the code for database calls because I just have to create or inject a new instance of the repository and then make those calls from the controller…

  • What would the controller section of the unreal engine be called or what components can be identified as controller parts (things that take data from a model and pass them to the view or maybe in this case the DX surface…

  • What would the view part of the unreal engine be called. I guess this would be when I push states of models into the drawing components but typically, what do you call these methods used for this a certain class of things?

  1. I love dependency injection and (IoC) to help test code… Is there a dependency injection framework for unreal engine to help me set up game states for testing… what’s common practice for this loose coupling functionality? This question really fits into what the controller sections of the unreal engine are… I might want to have a scene be dependant on components that I can test by injecting mock components into the scene… How does this kind of thing work… any links for help?
  2. When do you say, okay this really should be put in the code, or this really should be up to the level designer (also going to be me)… Do you have any guidelines on when to put things inside code or in the unreal engine UI… All that node stuff is useful for someone but I don’t know who :slight_smile:
  3. Final question for now is in terms of portability. Let’s say I make an Unreal engine game and then think, i’m going to port this over to OpenGL graphics library or put this all into a windows store application… Is there some built in interfaces for the graphics stuff… How do I take control over where the unreal engine instance is created so I can put this into a windows store app kind of thing… I don’t need to know all the details here, but more like, what can I expect when using the unreal engine, what control do I actually have…

Thanks for your time reading this, this will help me out loads!!!


Helpful information I have found so far for -
**
Seperation of concerns:**

  1. This is a tiny bit of a stretch, but think of the PlayerController as the Controller, the PlayerState as the Model, and the Pawn as the view. The idea is that control logic happens via the PlayerController which operates on the Model data which is replicated via the network with PlayerState object, and the Pawn is the visible representation (View). It’s not quite that clear cut, because the controller also operates on the Pawn. However, that’s a enough to get you thinking in the right direction.
  2. Not that I am aware of. However, we do have an automation framework (UAT - Unreal Automation Tool).
  3. That division really depends upon the project. My philosophy is to put cross cutting/supporting features in C++ and let designers handle the visual representation in Blueprints. Of course, that depends on what the task is but for world objects that has worked well.
  4. The engine handles the porting for you. We support a number of platforms that use OpenGL as the renderer. However, if you are interested you can look at the RHIs that we have created.

UE4 is very old school in it’s design. It’s pretty much classic object-oriented design, using modules and pluginsto help with separation of concerns. Modules can help with testibility as each module exports an interface, allowing a test fixture to be written against the API. No new-fangled ideas like IOC or MVVM allowed here, just an old fashion game loop: get input, update state, push to video system. Lather, rinse, repeat 60 times per second.

Haha, excellent guys, both very helpful!!!

I hope it’s okay to continue editing my original post with new information documents that help to answer my questions as well as your awesome responses!

Hi guys,

Thanks for the brilliant explanation. For me that was little bit unclear for a long time how to use UE4 parts in MVC/MVVM paradigm. For example in Unity i wrote MVC struct by myself using MonoBehaviour as base class, and “Instantiate” instead of “new”. In our own game engine that was similar to Unity’s approach, but based on regular cpp classes.

So finally for UE4:
> Controller = PlayerController + all AIController(s) on client and GameMode on server
> Model = Struct inside the PlayerState (there is no logic in PlayerState for me, only data) on client and GameState for server
> View = Pawn + independent living by themselves Actors in the scene
> ViewModel = another one Struct inside the PlayerState

The main problem was to get the right direction after reading that PlayerState is syncing between ALL clients in the multiplayer game, because they all are not want to receive my ViewModel :slight_smile: Also it’s always hard to understand how to apply classic patterns when your View (StaticMesh) is keepeing Logic (Blueprint) and Data (TRS) in a single object.

For example if we’ll talk about Hearthstone game:
349fd7f754f9bbb950b64ed376f583f776521fb6.jpeg