Wednesday, September 23, 2015

Unreal Engine Diaries #3

  • If we're displaying the game over screen as a widget that's added on to the viewport while the game is running, make sure that the game is paused using the 'Set Game Paused' command. Not doing this would mean that the actors in the level are continuously being updated in the background. Now sometimes it's fine to have the enemy actors move around the screen in the background, but even in those scenarios, it'd be a good practice to make sure that any constantly updating game element that's part of the player character/controller are turned off. An easy example to think of would be an actor in the level that is responding to the mouse cursor. So it might move around the screen, even while we're trying to click that restart button.
  • When creating a widget from within a task in a Behavior Tree, it's a good idea to make sure that it's not being called continuously. It's generally better to create widgets outside the task flow, within normal blueprints, but certain situations might demand widget construction from within Behavior trees in order to use some of it's functionalities that are not natively available in the blueprints. In such situations, there is a way to handle UI changes from the behavior tree tasks. Just add a 'Do Once' node inside the task before calling the widget construction logic. This makes sure that the subsequent iterations of the task don't create the widget unless explicitly specified. In my project, I've used this only in an end game scenario as one of the conditions for it was handled from within a Behavior tree task. It has since been replaced with a game pause call. So this makes sure that the Behavior Tree stops executing altogether, but the 'Do Once' node might be useful in other situations where you can't pause the game.
  • The world rotation of actors in a level, when broken down into their  x,y,z components lie within the range of (0,180) & (-180,0). When doing calculations based on actor rotation, this change in the values from positive to negative have to be taken into account. If we treat it like normal repeating cycles of (0,360), it might yield strange results in certain types of calculations.
  • When aborting a subtree in Behavior Trees, any task within that subtree that is actively running at that moment will not be aborted midway. It will see through to it's completion and if the task has delay conditions or code that changes some important data, this could lead to unexpected results if not taken care of. However it is possible to shut down these tasks at runtime through the use of conditional checks that gauge the current state of the game based on some external variable or blackboard values. Once we have determined that the task is to be aborted, we just call the 'Finish Execute' node to stop and get out of the task.