Hello.
I’m currently working on re-creating a game I wrote within Java using LibGDX but I’m running into some problems where I don’t understand exactly how I should replicate the structure of my game within Unreal.
The game is fairly simple in design, where you have two Teams, you press a UI button, that performs an action, then the other Team performs an action.
Within Java, I had a static Class called ‘GameObject’ where I would store the current Team ( an ArrayList of Actors ), and pass that into the gameplay section. I am just having problems understanding how exactly I should be storing the Team, creating each Actor, adding them to the screen, and interacting with them.
I was trying to create a Pawn that would act as my Team, but I couldn’t get it to spawn my Actors. My thought was that a GameMode could spawn that Pawn that would handle all the logic, and somehow pass the events from the UI to the Pawn but I’m not having any luck.
Any help that could point me into the right direction would be greatly appreciated.
I’m also using Paper2D if that makes any difference.
Thanks.
If you mean that structure is how actually replicate your game, then there is a little hints:
State of specified player (e.g. player only score) - APlayerState (one per player);
State of the game (e.g. team scores) - AGameState (one per level);
State of unit (e.g. knight’s health) - everything derived from AActor with bReplicates set to true (is unit).
Game play controller (e.g. how the game will played, what we should do when someone gets damage) - AGameMode.
A very core of a player (invisible watching ghost that casting commands which we can take control of) - APlayerState (one per player).
The last one is difficult to understand, it is like a bind of controller (gamepad, mouse and keyboard, steering wheel or whatever) and some view and listening point. We can control it by forbidding or allowing to move, giving pawn or taking it back, stopping input to play cutscene etc.
HUD is like addition to input and output:
Input - pressing buttons calling events.
Output - showing state of owning APlayerController (APlayerState inside of it) and/or owning player pawn.
And it is more likely to create HUD using blueprints, you can create C++ widget classes, but the most of visual and events are better to be in blueprints. Unreal Engine has visual scripting, use it in your advantage.
It sounds like I should be creating my Actors for each Team within a PlayerController, and then somehow binding the HUD’s input to the GameMode. But can I create a PlayerController for an AI opponent?
All my game logic should be within the GameMode ( such as creating the HUD, making the AI’s turn after the player goes, or checking win/lose conditions ).
I see that within my HUD, I can get the current GameMode, which I can use to call that logic, and within the GameMode, I can get the current PlayerController to modify those values.
Does that sound like I’m understanding you?
I’m creating the HUD within Blueprints, but I want to mostly stick with C++ for the core gameplay, such as creating Actors, and setting up the logic.
I don’t know idea of your game and even confused about it, but if your team is a single object, then one Team actor per… Player, or team of players… There is actually confusing moment. If per player, then pointer to this Actor must contain inside of PlayerState. If per team of players then Team actor and PlayerState of each player must have team index, indicating in which team they are.
The idea of UE4 is 1 actor per one local object. If we have for e.g. chess, then each piece will be a separate actor, board is just mesh (or picture), and pieces positions stored in GameState (through moved events in GameMode).
PlayerController is just one variant of Controller. There is AIController also, acts just like PlayerController, but don’t have input, camera, HUD and other things, that human needs. Spawns in game on demand or automatically if need to possess specified Pawn (Actors and Pawns are not the same, only Pawns can be possessed and controlled).
Yes, your global game logic should be within GameMode (even if Pawn receives damage it should ask GameMode about health manipulations). HUD is only PlayerController’s thing, it is what human need to see what is going on.
Well, HUD is additional input, basically it shouldn’t directly send events to GameMode. PlayerController is class which receives any input and broadcasting (or deciding to broadcast) to where it is needed. If for example you need to make a move in network multiplayer then you need to send message about it from HUD to PlayerController, PlayerController will raise this message to server level (HUD of clients does not exist on server) and then server will decide what to do.
Blueprints are useful in small calculations, time based sequences and HUD, all of your game can be created using 100% of C++, but I meant that it will be much easier and faster to create HUD using blueprints. In my game I have my character 70% C++, 30% blueprint and that’s okay.