x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Where to locate overall game handling logic?

Lets say I have RTS game application. The user is starting the game app, first he should see a main menu:

  • Single Player

  • Multi Player

  • Options

  • Quit Game

I mainly use C++. The main menu is based on a widget blueprint and handled by a user widget class implementation. In a prototype game app I made the main menu working by initializing it at BeginPlay in a PlayerController, just for test purposes. But if the main menu is used to load e.g. a single player map it runs into ugly logic not showing the main menu, because BeginPlay is called each time when loading a map. I'm always facing the problem that my logic is badly misplaced due to not having information of how the UE4 game play framework components stick together. In the particular case I am asking myself where to locate the main menu handling code, due to it's overall for the game application.

At the point where the main menu appears, there is the starting point of my game application, and there is nothing specified what game user wants to do, but there is already setup a default for everthing. After the game user has made a choice at the menu then it's known what to do next, and how to setup the specific game requirements. I know there is a GameInstance, GameMode, GameState, PlayerState, and what they intended to be used for, but it's puzzling how they associated exactly together. They all come into play somehow in a magical way. Especially how to design a game architecture that fits plenty to even single player and multi player.

I have a few questions regarding the UE4 detail design:

  1. How is the startup sequence of an UE4 game application? Which UE4 game play classes are involved?

  2. How is the composition design of the game play framework instances?

  3. Where to place best a overall game handling logic, for menu, to load maps, to specify single player or multi player behaviour?

  4. Do I have to implement a special PlayerController, -GameInstance, GameState, only for menue handling?

  5. How to handle multiple game modes, multiple player controller types?

  6. How is the sequence when loading a new map? How, and at which location to get control of specific game framework instances?

  7. What is the Root-Object of the Gameplay Framework the game programmer can get control of, is it GameInstance, or is there something before?

Product Version: UE 4.8
Tags:
more ▼

asked Aug 04 '15 at 05:17 AM in C++ Programming

avatar image

caribes
31 4 6 8

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Hi,

i'll try cover basic things, you should know i prefer blueprints to C++, but core idea the same:

  • base building block is level (map) asset, it define various parts such as: 3D terrain of your level (for both case, static world and partially dynamic up to fully generated piece by piece at runtime), so maps can separate how your game works, you can make universal maps that work both in single and multiplayer, also you have to know that "Main Menu" actually usually just a level to handle base menu navigation to all other activities in the game and at same time provide some light background, from 1 flat image up to fully 3D dynamic composition, from this point you can your project settings by default to "Main Menu level" in this place https://yadi.sk/i/4TeIM3xRiFpn6, al note that each level have own "level blueprint", it's a special place for default loading logic

  • more likely every object as blueprint can have "event begin play" to let you controll what should happen after object was created, it remain same for levels in their level blueprints, so when level loaded from this event you can handle what should happen next depending on level and game mode preferences, note that same level can work fine for different game modes and single/multiplayer if properly set

  • good idea is make your own player controller blueprint/class for handling most logic flow like mouse and keyboard clicks, this is right place to store all data related to player and not properties related to instance of your units like their HP, armour, speed - such should be stored in actor based blueprints/classes and in player controller should be stored things like player's current resources, relaitionship with other players, choosed start race, place, units, role, this blueprint/class is also a place from where you want create menu widgets and HUD, to access them later after creation don't forget store widget/hud reference into variable, so later you can simply use "get player controller" in blueprints (don't know analog in C++) and get access to widget/hud

  • since you asked about RTS between actual playing level and main menu level also should be lobby level where host can specify game settings and player can connect

  • single player and multiplayer setup doesn't differ really too much after proper multiplayer setup, single player will work like playing on host player alone (but without network activity when single player), here's how achieve multiplayer setup - it's just set of basic properties on right things, list below:

  • variable replication - it's just a drop down menu when any variable selected in any blueprint editor (don't know how setup it from C++, it's up to you to find) and here are 2 types, just "replication" and "rep notify", they're the same, except "rep notify" have a specific function for each variable with such property and fire it on each client when this variable get replicated to allow manual flow control when things changed (for example you can use rep notify to file manual flow control when player offer ally to another)

  • actor blueprints replication and relevancy - replication just share actor's inner properties (like position, rotation, material on mesh and so on) and not variables such blueprints can have, because each variable have separate replication property; relevancy is used to control flow in case when one player doesn't know what happen to objects too far from him (probably it can be used to manage "fog of war" and hide units from player until his unis close enough on server to see them, you may heard about "maphacks" for RTS genre, so this hack usualy possible due wrong replication setup in other engines)

networking example on actor replication and relevancy from epics (and not only this topic) can be found here launcher->learn (scroll down to "Engine Feature Samples", because there're just docs link on top)->content example (click it and inside click download)->library (after download complete press "create project" on content example); after opening this project open level called "networking" from file menu (here are also other levels for other topics)

  • custom events - this is special type of events that can have several replication properie (only one type per custom event), to create one in blueprints i usually simply right click and select "add custom event", how create it in C++ up to you to find, the propety in blueprints lay on left side in detail panel and called "Replicates", it can have one value:

not replicated - this one fires only locally on each client and server;

run on server - this one used by clietns to ask server execute something (remote procedural call);

multicast - replicate this even from server to everyone else;

run on owning client - replicate this even from the server to owning client

their visual functionality can be seen in networking example of content example project;

  • function - "switch has authorty" it's also various part of multiplayer setup, this function controll flow of execution and prevent doing things on clients when action must be performed by server only, can be used to implement one function which differently work on client and server

p.s. if you didn't got idea on something various, try ask again after reading this, because your understanding may change and note i described common knowledges to properly setup multiplayer and some other thing, how you would implement final multiplayer/game up to you, same result can be achieved in different ways using this

more ▼

answered Aug 04 '15 at 08:45 AM

avatar image

happyhorror
576 53 45 72

avatar image caribes Aug 05 '15 at 02:11 AM

Thanks for your extensive reply. I will check your hints. I think it will improve my understanding on the long term. Probably I should work out my game a bit more and see how it behaves in a multiplayer scenario.

avatar image soundyogi May 16 '17 at 05:20 PM

wow thanks this was such a good answer!

could you elaborate hoe the gameState fits in all of this?

I keep reading that 'everything in the gameState is important for all server stuff' What does that mean? Does it replicate automatically?

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question