Unreal Project 1

In an attempt to diversify my programming tools, I’ve taken it upon myself to learn about how Unreal Engine 4 works. On top of that, I’ve been itching to work on another first person shooter, and found a good opportunity. I came in knowing absolutely nothing about Unreal, and spent a lot of time learning the basics.

The original goal was to create a networked game that implements basic first person shooter mechanics. This way, I’d learn a lot about the engine’s basics (spawning, object instantiation, ray casting, collisions, etc…), while also learning how networking and synchronization compares to something like Photon or UNET. Here’s what I’ve got so far:

 

The FPS Character

Overriding the FPS actor, I’ve added a third-person mesh and separated the first person animations, by making them only visible by the local player. I’ve also added:

  • A weapon & ammo system
  • A health system, which ragdolls the player on death
  • A task system: this handles player states, like reloading, shooting, etc… via requests to the server

Health

The health system keeps track of and synchronizes the player’s HP. When the player collides with a bullet, an override of Unreal’s TakeDamage function is called, which handles health.

The more complicated stuff comes from what happens when the player dies. OnDeath is called, which tells the player’s third person mesh to simulate physics (a feature that is turned off so that the FPS player has control over movement). A physics asset was generated for the mesh, making this happen:

The boolean for death is set and replicated (synchronized). The simulation is turned on, the player collision is turned off, and the mesh is desynced, since ragdoll information doesn’t need to be networked.

Ammo

The ammo system is pretty straightforward: bullet objects are instantiated when the fire task is executed, so long that the player has ammo.

There’s a different value for the ammo currently loaded, the size of the magazine, the total ammo held by the player, and the maximum amount of ammo that can be held.
There’s a timer handle for reloading and controlling the rate of fire. Reload just starts the timer that’ll refill mAmmo, stops shooting, and plays an animation (if I had one)

Tasks

The task system is handled by a replicated enum

I bind input to these functions, which call PerformTask on a specific type of task, doing this sends a request to the server to handle the task. The server will then call the function that fires, reloads, etc…

So when left click is held, OnFireStart is called, which hands the FIRE enumerated value to PerformTask. If the local player is a client, they will ask the server to perform the task for them, by calling the ServerExecTask RPC function.

 

Map Pickups

I created a class for objects on the map that’d be picked up.  Things like power weapons, health boxes, and ammo boxes can extend this class to override an OnPickup function for when the player steps inside the pickup’s trigger volume.  This way, new pickups that do unique things can be made extremely easily.

One picked up, the item calls a despawn function, which either temporarily disables  the object and sets a timer for respawn, or destroys it entirely.  The mEnabled bool is networked and dictates whether or not the item should appear with an active trigger.

 

HUD

Lastly, I started messing around with blueprints, which I used for the player’s HUD.  Here’s what my blueprint for the health function of the HUD looks like:

It’s a pretty basic first-time blueprint used with the UE4 HUD widget, which grabs the local player character, accesses their HP, and converts it to the necessary display type.

Leave a comment