• Advertisement
  • entry
    1
  • comments
    0
  • views
    213

About this blog

This blog is dedicated to my personal research and implementation of computer games.

During the journey, I'll study how different games could work and how they could be implemented by using some modern techniques. 

Blog continues the journey that started in https://toivjon.wordpress.com/

Entries in this blog

It's been a quite long time since I previously used Unreal Engine to build games. If I remember correctly, the previous game was some kind of first person horror adventure game where the player was exploring the darkness in some kind of mansion or such. This mansion contained faceless doll creatures that would attack the player when certain conditions were met. Game had no weapons and player was only equipped with a small flashlight that allowed him/her to explore the mysterious rooms of the mansion. This project was a school project we created with my three classmates when I was studying my bachelor's degree in Turku University of Applied Sciences. So it's been around seven years since I previously touched Unreal Engine. And now, I decided that it's a time to dive back into the world of Unreal Engine and create something super cool... like an another Pong clone!

Installation of Unreal Engine

The installation process for Unreal Engine is quite interesting. Before the installation package could be downloaded, I needed to create an Epic Account. This account was then used to download the Epic Game Launcher application which was then used to install the actual Unreal Engine. I'm not sure why the installation needs to have so many steps, but perhaps Epic has good reasons behind it.

Installation was now complete, and it was a time to start the engine. During the startup it started to compile shaders, which took a while. I also had some problems with the Visual Studio linkage as the engine throw some errors about how it failed to compile sources for the project. After some googling I found out that I needed to install "Game development with C++"-module to my Visual Studio to get this link to work correctly. After installing the module, I was able to start a new project without errors and now I was ready to start my journey with the engine.

Scenes

As with my previous implementations, I decided to use three different scenes. One scene for the main menu, one for the in-game court and one for the results screen shown after the match has ended. This kind of scene set requires only the following three transitions.

  • main-menu --> court, after the player has selected the "Start Game" menu option.
  • court --> end-game, after either player has reached the score limit.
  • end-game --> main-menu, after the enter key has been pressed.

In addition, we also have a special transition, which starts from the main-menu and exists the application after the user selects the "Exit" menu option.

If I haven't understood completely wrong, it seems that Unreal Engine calls scenes as levels. This makes my scene split quite interesting, as now I have a main-menu level and end-game level in my implementation. Somehow I feel that I've done something in a bit odd or wrong way.... But it works!

Main-Menu

I decided to follow the same main menu structure what I used with my other Pong implementations. This view contains only four different components that should be shown on a top of each other. One label for the game title, another for the menu usage instructions and two buttons which are used to start or exit the game. This kind of simple structure would provide a nice way to get known with the basics of the user interface system in Unreal Engine.

Unreal Engine seems to have a support for basic and even complex user interface constructions via the Unreal Motion Graphics (UMG). After watching a couple videos, some tutorials and documentation, I managed to implement a simple user interface for the main menu. See the following images.

main-menu.thumb.png.9ba7028c6a2f92b2570c847ddf3a0e5e.png

main-menu-blueprints.png.928a5c751cadc03e588ebdcc17c55aa1.png

Thanks to blueprints, this was super easy to do. I only needed to add couple click-listeners and wire them with some simple navigation commands to get the transitions to work. Blueprints are actually reminding me of the old Kismet(?) system that was available in some version of the engine. I have to admit that I usually prefer doing all logic by coding it line-by-line. Still, creating the graphical user interface logic with a graphical tool felt natural. Perhaps it's a psychological thing or such.

To get the main-menu "level" working, I also needed to modify the level blueprints so the level would create and attach the main menu widget to viewport when the game starts. See the following image of the blueprints that were used as the level blueprints when the main menu was created.

main-menu-level-blueprints.thumb.png.594b24a5160a6283f43daae430c2d996.png

This blueprint contains the same kind of logic that is actually used in quite many tutorials. And it works! At least for this kind of small game.

Court

Now it was a time to move on to implement the court scene. For this scene, it was quite clear for me to follow the same kind of structure that I used with my previous Pong implementations. This structure contains two movable paddles, one moving ball, two collideable walls, two invisible goal areas, two non-collideable score markers and a one non-collideable vertical center-line at the center of the screen. This structure can be seen from the following image.

pong.png.c8a4a46a0320f652b38cf9b4585da919.png

The previous image contains flags on each entity to mark the behavioral role of the entity. C is for collideable entities, which may interact with other entities. V is for visible entities that are rendered i.e. can be seen by the users. M is for moving entities that can move around the scene and P is for entities that are acting as player avatars i.e. can be controlled by the players. This kind of notation helps (at least me) to implement all items for the scene.

With my previous Pong implementations (i.e. JavaFX, JavaScript, SDL2 and Unity) I used geometry generation support to create graphics for the entities. This time, I decided to use the Unreal Engine's Paper2D sprite support to create visuals for the entities. I managed to use GIMP to write the following kind of sprite sheet for the court scene.

pong_sprites.png.56d56d7adcaca085d93ac7f5b8212162.png

Well... I'm quite sure that my sheet does not follow the "industry" standards how sheets should be created but it works! There's some redundancy on some elements and such, but I wanted to e.g. keep paddle and number one as a separate element in the sheet and also to keep the ball separated from the middle line sprite section. The sheet used in the game differs from the image shown here as it has a transparent background. I also decided to use TGA as I heard and read about some transparency problems with the PNG, which made this as the first time I used TGA in any of my games.

Now it was a time to start creating some logic for the game entities. I first started with the C++ API but found that there were too many C++ monsters along this road. One of the monsters was that there were strange communication problems between the Unreal Engine and Visual Studio which made my source files to be opened multiple times. I even faced a a monster which did completely collapse my project so I couldn't event re-open it before I manually deleted some of my "invalid" code structures from the project. I'm quite sure that the C++ API is great when studied thoughtfully but I decided to take a shortcut and leave the huge C++ API aside and take the Blueprints path.

I had a bit confusion about where to store the actual game logic as there seems to be multiple suitable layers. I also found out that there is no actually a "right place" to put it as people seemed to put it in different places depending on the size and the features of the game. I decided to scatter my game logic into multiple places, where the level blueprint was acting as a centralized router for global events. I think that this worked quite well as the level blueprint has a good ability to directly refer to all actors available in the current level. After I did some study about how the event passing mechanism works, the communication between the game entities was quite easy to implement. 

I also had a requirement where the game results needed to be passed to end-game scene where they could be shown to players. I first thought that it would be quite trivial to implement this in a elegant way. However, I found out that my game results were attached to a wrong place as I needed a storage which would persist across the scene changes. I googled a bit and found out a solution to use a custom Game Instance to store this kind of data.

And then I finally managed to get all logical pieces gathered into a working solution.... 

ingame.png.8093568813ed01f0bca5463ea874510d.png

Afterthoughts

I must admit that Unreal Engine is huge! It has lots of cool features and a support for many platforms and things that I haven't ever heard of. Those things that I learned about the Unreal Engine C++ API and Blueprints were only a tiny scratch of the whole set of functionality that awaits within. It's not a surprise that Unreal Engine is a globally popular game engine in game studios. I also think I managed to get a quite well working implementation for my game and perhaps I'm going to dig deeper (and even try the C++ API once more) with some later project.

Thanks for reading!

Game source in GitHub: https://github.com/toivjon/ue4-pong

  • Advertisement