Categories
Final Major Project

Game istance, casting, inheritance UE5

The final result is shown in the video above. The process is described below.

During the setup for this project, I’ve explored and implemented a basic game logic system in Unreal Engine that integrates real-time data from an Arduino device. The first important concept is the Game Instance.

The Game Instance in Unreal Engine allows to store data that persists across all levels. It effectively acts as a single source of truth, holding all global variables that other Blueprints can access.

In my case, the animation system is driven by real-time data coming from the Arduino. The Arduino sends sensor values to Unreal Engine via a serial communication plugin, which I handle inside a dedicated Serial Communication Blueprint.

Here’s the overall data flow:

  1. Arduino → sends sensor data.
  2. Unreal Engine Serial Communication Blueprint → receives and processes the data.
  3. Game Instance (GL_logic) → stores the processed data globally.
  4. Character Animation Blueprint → retrieves the data to drive animations.

This order follows Unreal’s hierarchy (heritance) and data flow principles. It would be incorrect to try to reference the communication Blueprint directly inside the animation or main game logic Blueprints. Instead, Unreal uses a system called Casting to access data or functionality from another object.

In the Serial Communication Blueprint, I perform a cast to the Game Instance (GL_logic) and set a variable called Intense with the mapped Arduino value.

The process looks like this:

  • The Arduino sends data as a string.
  • The Blueprint reads data (serial read line function),converts that string to a float.
  • The float is then mapped from the Arduino’s range (0–255: this is the range of values which are predefined within the code logic) to a new range (0–100,000 this is the range value used for the light intensity).
  • Finally, this mapped value is stored in the Intense variable inside the Game Instance, which acts as the global data container.

Then, inside the Animation Blueprint’s Event Graph, I use the Get Game Instance node, cast it to my custom Game Instance (GL_logic), and retrieve the value of Intense. That value is then assigned to a local variable called SensorIntensity inside the Animation Blueprint.

This local variable (SensorIntensity) is used as a threshold within the State Machine to determine transitions between animation states.

For example, in my testing setup:

  • If the mapped Arduino value exceeds 70,000 (roughly 70% of the mapped range), the character transitions from the Idle animation to the Walking animation.

This system allows me to achieve real-time, data-driven animation, where the animation is not pre-rendered but responds dynamically to user input and sensor data.

In summary, this setup demonstrates:

  • The use of the Game Instance as a persistent global data store,
  • The use of Casting for cross-Blueprint communication,
  • And how the data flow follows Unreal’s inheritance and logic hierarchy to connect Arduino input with character animation in real time.


Animation – state machine

The Animation Blueprint class is created using a Blueprint that’s assigned to the same skeleton as the character you want to animate. It’s essential that both the character and the Animation Blueprint share the same skeleton; otherwise, the animations won’t work correctly.

Once the Animation Blueprint is saved, it can then be applied to the character in the Animation section of the character’s details panel, under the Animation Class of the character mesh.


Resources:

Animation State Machine: Unreal Engine 5 Tutorial – Animation Blueprint Part 1: State Machines

Main Game Component: How to use the Game Instance In Unreal Engine

Casting: A COMPLETE guide to CASTING in Unreal Engine 5!

Leave a Reply

Your email address will not be published. Required fields are marked *