Getting started with Unreal Engine 4

Hello Folks,

I am a Unity user(no real projects, just a hobby) trying to learn about Unreal Engine. I’m starting to navigate the interface, it’s C++ and blueprints I’m having a hard time with.

In Unity we can use the hierarchy create a parent Game Object which we can use to run the code sequence for our games. We can use the object’s void Start() method to load whatever we want into the game, and use the Update() method to run the game loop in. The best project that I ever did in Unity was a streetlight simulation. The flow was something like this:

  1. Initialize Materials used for the light bulbs, set up basic gameplay elements in start Method
  2. In update method, control the material where the countdown timer is(Green material if countdown timer is Greater than 15 seconds, yellow material lower than 14 seconds, greater than 10 seconds, etc)
  3. repeat

In Unity, it takes one sheet of code and about 100 lines or less to complete the whole simulation.

Unreal Engine seems quite different, but I think I’m starting to get the workflow down a bit, so please correct me if I’m wrong. BeginPlay() Override is Unreal’s Unity Start Method, and the Tick(float deltaseconds) override is Unreal’s Unity Update method. This is housed in GameModeBase that is sort of the GameManager that you use to initialize your game and update your game loop.

The problem I’m facing is, where is main? Where in the default project setup do you start your game? I’d like to do a simple GEngine->AddOnScreenDebugMessage. I have a StartPlay override function, but when I try to call Super::StartPlay(), I am told that UObject has no instance of StartPlay(), and so there’s no where to start my code sequence. I now realize that Super::StartPlay() is usualy called in Actor components, but I think I can use it in GameModeBase, right?

Sorry for very basic questions. I have been following tutorials on the website, like the first person shooter tutorial in the documentation page. I am running the latest update of Unreal + Visual Studio. Can someone create a basic C++ template of a streetlight simulation that I can follow? Thanks!

AGameModeBase inherits from AActor (via AInfo), so yes, you can use/override the BeginPlay() (not StartPlay) method. If you are only wanting to create a single level, then you could also use the level blueprint and run your setup code in the BeginPlay event in the level blueprint.

If u are new to unreal and learning the logic of how a project is build/setup, i would suggest starting with blueprint.
Personally i prefer to do my entire project in C++, but blueprints is easy for prototyping, no compile time, so fast the change and test.
So sometime i use blueprint and when im happy with the result i write the C++ classes based on the blueprint.

As for your streelight example, in UE4 this logic would most likely go into your streelight actor, where u create an actorLifeTime variable and in the tick method, u increase the variable with the DeltaTime, then change your material based on the lifetime of your actor.
In case of countdown instead of lifetime, your BeginPlay method of the actor would set CountDown on 15.0, then decrease in the Tick
A game mode would contain logic like ending a round if certain time elapsed, player gained certain amount of kills/score …
U could put your light countdown code in the game mode, but then in the tick, u would have to iterate trough your light actors to update them.

The game mode is basicly the rules of a single round.
I also used Unity before UE4. Its a higher learning curve, but once u get the hang of it, u will see that it’s easier to work with cause of it’s structure (GameMode, Pawns, Controllers, …)

In Unreal you’ll mostly want to initialize things in their own beginplay and update them on their own tick, so probably do that lightbulb stuff on the object.

Thanks for the replies.

My next question is how to be able to call Super::BeginPlay() and Super::Tick(float deltaseconds) in my gamemode .cpp file? These methods are not found in Visual Studio’s intellisense.

I also have the same issue as this guy: https://forums.unrealengine.com/deve…le-generated-h and curious how to fix it.

I also have this “Loading Visual Studio 2017” tab on the bottom right of my screen that never goes away even though visual studio is loaded. If close visual studio and try to re-open it inside Unreal, I get a message: “Could not open Visual Studio 2017 for project: C:/Users/Ryder/Documents/Runreal Projects/MyProject5/MyProject5.sln”. Any ideas?

Intellisense sucks, unfortunately - and it won’t find half the things you need. Your best bet is to just look at the parent header file to see what functions are available for you to override (I’d also recommend investing in Visual Assist X - it’s a better intellisense and more, and actually works).

Nothing you can do about the generated.h file warning, but it’s not a problem anyway (it won’t stop you compiling - and those headers don’t exist until compile time anyway).