Wednesday, October 25, 2017

Tower Defense Starter Kit Tutorial: How to create a new level

1. First ensure that the default Game Mode & Game Instance class parameters in the Project Settings are set to BP_GameMode & BP_GameInstance classes respectively.

2. Now create a new map, open it, & lay down the navigable area for AI bots by placing instances of BP_AIPath across the level. Add a Navmesh Bounds Volume & extend it to encapsulate all the AIPath actors.


3. Add a Lightmass Importance Volume around the core game space.

4. The BP_AIPath actors that we added earlier has a secondary function apart from providing a traversal space for the AI bots. And that is to allow the deployment of Global Abilities like Airstrike. Everytime a player selects a global ability, a targeting reticule is activated to point the precise location for deployment. However if we have empty spaces in the level, this can be an issue as there will be no surfaces to block the GlobalAbilityTargeting trace channel. In order to rectify this issue, the toolkit provides a solution in the form of the BP_PlayerMovementBounds class. While it is an invisible actor, it can block all types of trace channels, & thus provide a platform for displaying the targeting reticule even when there are no underlying meshes under the cursor location.

So the next step is to add a BP_PlayerMovementBounds actor just below the lowest point along the AI path. Now set it's 'Trace Blocker Extent' parameter to cover an area larger than the maximum visible game space as seen through the player camera. With that, we have essentially added the ability to use Global Abilities.

Now onto the primary functionality of this actor. As the name suggests, this actor can be used to restrict the movement of the player camera. The movable space for the camera is determined both by the 'Tracer Blocker Extent' value as well as the 'Blocker Bounds To Movement Bounds Ratio' attributes [check screenshot below]. For example, the default ratio of 3.0 to 1.0 ensures that the player camera can move around in an area corresponding to middle one third of the space covered by the actor's trace blocker volume.



5. Since we've already laid down the paths for the AI bots, the next step is to add instances of BP_EnemySpawnPoint along the paths to act as spawning points for the enemy waves. As can be seen in the next screenshot, I've added a couple of spawn points in my level:




6. Now add a BP_ExitPoint actor somewhere along the path to provide the primary movement target for the enemy AI bots.

7. The toolkit uses modular grid generators to act as platforms for tower placement. But before adding them into the scene, first add a BP_GridManager actor. Use it's publicly exposed variable 'Grid Cell Size' to specify the size of the individual grid cells across all grid generators in the level.

8. With the grid cell size specified, it's now time to add the grid generators. Drag & drop instances of BP_GridGenerator into the level. The overall size of the generator in the X & Y (local space) directions can be specified through the 'Grid Count X' & 'Grid Count Y' variables as shown below:



9. Now add an instance each of BP_ProjectileManager & BP_ObjectPoolManager into the level. If you plan to use the pooling system, just set 'Pool Bullet Projectiles?' to true through the details section of the actor. Since this system uses a fixed size pooling system, also make sure to specify the pool size through the 'Pool Size Bullet Projectile' variable.




10. Now comes two of the most important classes required for the functioning of the toolkit: the Tower Manager & Wave Spawn Controller. Add the BP_TowerManager actor first. There's no need to make any changes to it's default parameters, but if you want to know more about the class, check out the concept overview post for the same at: https://forums.unrealengine.com/unreal-engine/marketplace/74591-tower-defense-starter-kit-support-thread?p=685390#post685390

Next, add an instance of either BP_BatchedWaveSpawnController or BP_WeightedWaveSpawnController to the level. While most of the default parameters will work right out of the box without any need for customizations, you will have to add references to the enemy spawn points within the publicly exposed array 'BatchedWaveSpawnDataArray', if you're going for the former model. Just make sure to specify the 'SpawnPoint' for each wave by linking it to one of the spawn points added to the level in Step 5.




For further reading about the wave spawning systems, see:
11. Now onwards to the final step. All that's left to do is to add level bounds so that actors like projectiles that BP_LevelBounds can move across the level gets destroyed once they cross a certain threshold. Add six BP_LevelBounds actors along the outer periphery of the level, making sure that they form a cuboid shape to encapsulate the entire level.




With that, you should have a fully functional level at your disposal. If you have any queries regarding the workflow, feel free to let me know in the comments section.

If you're interested in the toolkit, you can purchase it through the Unreal Engine Marketplace: https://www.unrealengine.com/marketplace/tower-defense-starter-kit