How to actually begin programming a game?

I am sorry for my phrasing of the question in advance, I am not sure how to ask about things that I want to know. Watching guides for unreal engine 5 makes me feel similar to back when I was learning programming and not a single lesson said that program starts with
“int main(){
}”
My best result, so far, which is nowhere near what I would call finding an entry point was in unreal engine → tools → new C++ class and selecting “pawn” which I called “TestingPawn”… It generated some code which I have successfully modified into “hello world” program after including “Kismet/KismetSystemLibrary.h” and having a line:
void ATestingPawn::BeginPlay()
{
Super::BeginPlay();
UKismetSystemLibrary::PrintString(this, “Hello World!!!”, true, true, FLinearColor(0.0f, 0.66f, 1.0f), 20.f, NAME_None);
}
And then creating a blueprint with a class TestingPawn in the engine and dragging an instance of it onto the map… But, its nowhere near of what I would consider an entry point… First of all, where in the world did it include the new files? If I write some “MyLibrary.cpp” where is the proper place to include it? Where in the world is “TestingPawn.generated.h”? Like, physically, I have found it in “Intermediate” folder, but visual studio does not see that folder… I shouldn’t even have to drag something onto the map for an effect or even create a blueprint like that… there should be an entry point where I type something like “spawn(TestingPawn)”, but no guide seem to even begins to mention it…

Being a programmer/coder myself, when I started with Unreal Engine it was with Blueprints. This was to get a basic unerstanding of its concepts and framework. Later then I started replacing the Blueprint functions with cpp code.

  • “If I write some “MyLibrary.cpp” where is the proper place to include it?”
    The same as with any other cpp project, you include your library in the classes where you need access to its availabe functions or variables.

  • “Where in the world is “TestingPawn.generated.h”? Like, physically”
    This is what ChatGPT is telling about .generated.h files, I couldn’t explain it any better:
    "In Unreal Engine, generated.h files are auto-generated headers that play a crucial role in the Unreal Engine build process, especially in the context of Unreal’s reflection system and the Unreal Header Tool (UHT). "

  • “I shouldn’t even have to drag something onto the map for an effect or even create a blueprint like that”
    Correct, but your code is only used if in some way it has a reference to an object that is placed in the map. There is no need to create a Blueprint, you could drag the cpp class directly o the map as well.

Regarding your ‘hello world’ test, use this code after Super::BeginPlay();

if (GEngine)
{
    // Print "Hello World" to the editor log and screen
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Hello World"));
}

If you would like to start with cpp right away, I recommend to check out the code of one of the default c++ project templates.

Even Unreal has ‘main’ function, it’s somewhere deep in the code of the engine core :slightly_smiling_face:

Yes… But like, I need some sort of starting entry point… Something that creates the world based on some rules… In like 90% of the games that I play map gets randomly generated, before the play even begins. The idea of creating a pawn and probably calling it “LiteralGodPawn.cpp” and dragging it into the level seems wrong. I feel like there is supposed to be a proper entry point somewhere… I feel like just creating an actor/character/pawn or what ever default option there is just adds a lot of unnecessary functionality to something that just meant to be an entry point.

There is somewhere where I should start with things like “open game menu for user”, before even anything the game has loads…

There is no exact entry point as you might know from your other projects. But that is the same with any other game engines. They provide basic default classes as an entry point, that you can use and modify as you need.

There is no need to start with the main pawn, you could start with the map or with the game menu or whatever you prefer.

Many developers start with the main pawn, in order to be able to ‘move around’ in their level and to be able to check how it fits with other objects in the map. Others start with the level layout, blocking out walls, creating landscapes etc. There are no fixed rules, only best practises that may speed up your workflow.

1 Like

After trying to study it for a while, it feels like “game mode” class is the best entry point… I have found that one can select default game mode class in settings for the project and then it feels natural to start from there by selecting player controller and such.

Or… even better for my purposes is “game instance” class, but it is not used in any of the examples.

Don’t hyperfocus on c++, start with just blueprints, use c++ when blueprints isn’t enough, or even to edit blueprint classes to make them be enough.

You’re not gonna make a full fledged game in unreal without using both heavily, but generally I think people always start their unreal projects with blueprints, only going to c++ when there’s an actual reason to use it over blueprints (this would be either performance reasons, or just a limitation of blueprints).

I feel like you’re thinking about this the wrong way, don’t try to start making a game, by starting to make a whole game from nothing, if that’s what you want to do then you might as well start with making the game engine :laughing: also consider the possibility that godot might be better suited to you, it’s easier to learn and use than unreal if more limited in scope (but less so than you’d think).

You need to start smaller, implement just one feature, like say go make a third person blueprint and try to figure out how to make the character wallrun or double jump or crouch or zoom in to first person or hold a gun… Just figure your way forward one feature at a time, then when you’re well and proper comfortable with the engine you can start over from a blank project, copy pasting the code you can still use that you’ve been playing with, and starting over on some of it that you would like to do better.

Don’t try to learn everything all at once, you’d be destined to fail, nobody learned blender in a day, and unreal is a lot more complex than even that.

Honestly, I am trying to implement what would be one feature from my perspective… Its just, the features that I am trying to make do not really seem like what developers usually make… The first feature that I am trying to make is procedurally generating a world from player input… In my head its:

  1. Game start.
  2. Ask for player inputs such as size of the world and its type.
  3. Store that data and generate a world based on it.
  4. Let player walk within generated world.

An example game that has what I am trying to start with would be “matchless kungfu”, in that game, you start with a blank world and you place tiles to expand it. Well, technically it is several features, step 4 is basically done in unreal engine by default… Making a player input screen is a feature that I have put for later and I started with step 3, generating a world, but, I need an entry point… Like, if I was working in pure C++, I would do something like this:


int generate_world(int size_x, int size_y, int other_options){
   // do things
   return 0;
}

int main(){
   int default_x=256;
   int default_y=256;
   int default_options=0;
   if (generate_world(default_x, default_y, default_options)==0){
       // make player enter it;
   }
}

Then after learning how to generate thing properly, I would test it with different defaults, they work on the feature that allows player input instead of using defaults.

I want to compile the answer that I have found.

First of all, this video is great, https://www.youtube.com/watch?v=ejGfHtgGOOI
It gave answers to the questions that I had the moment I opened unrealengine5 for the first time, but did not know how to formulate those questions. I wasn’t able to perfectly recreate it though, just adding files in visual studio did not work for me, but it works fine if files are added through unreal engine tools → new c++ class.

I want to add some other useful information for what I have understood. First of all, “BeginPlay” can be used as an entry, engine calls BeginPlay of every object existing in the world, additionally there are objects that do not have to exist:

  • Level blueprint. Accessing it is non intuitive though, you need to press one inconspicuous button in editor which will give access to “open level blueprint”. The before mentioned video does press that button, so it can be used for reference.
  • PlatformGameInstance. There is only one copy of that object, so its great for entry, it is created the moment you press play. I would consider this the most universal entry point. Instead of “BeginPlay”, the entry has more intuitive name “Init”
  • GameModeBase. Its the entry point that is used in many free examples. It is tied to the level, when ever a level opens, it runs game mode associated with it. To add game mode to a level, one needs to select the level in content browser and on the right → world settings → GameMode Override.

In unreal engine, you can select the defaults for those classes by going to Edit → Project Settings → Maps & Modes. There you can select default Level which in there called “Game Default Map”, you can also select default game mode and default game instance.

PlatformGameInstance is superior entry point, because in there, you could connect “OpenLevelByName” to the “Init” and have a game mode override connected to the level that you are opening, only data stored within game instance is transferred between different levels, everything else is terminated and lost. Though, it does open the default level and game mode and runs their BeginPlay, before it runs Init in game instance(not exactly, its kind of weird what it does).

Additionally, the most useful hotkey to know is ctrl+alt+f11 which makes a quick recompile refresh in unreal engine editor after you change source code.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.