9 Dec 2020 16:12
Object-oriented programming with Class Blueprints
This is just a small update to share something we created while exploring Class Blueprints: Unreal Engine's approach to visual object-oriented programming. If you're familiar with the concept of objects within programming (from any language), the term class should give you a sense of how these work. A Class Blueprint is a way to build the geometry, data and behaviours/functionality of an object in Unreal Engine. After defining a class blueprint (for an Actor for example), it's possible to generate as many actors based off this class as you like.
As a quick test a few months ago, I (Thomas) decided to try and create a class blueprint around the idea of a coloured light. It would essentially be a point light with a visible sphere. Each object should be able to receive a unique colour to apply to its point light and the emissive material on the sphere to make the light source visible. Here's how the scene came out in the end...
The actual blueprint
Each Class Blueprint has an event graph to create a node-based program. Starting with the BeginPlay event (which fires once per object at runtime), a random vector is created and multiplied to appear anywhere with a 5000 unit radius from the centre. I've mapped the Z value to keep it above ground. This is all for the position of the light. To generate a random colour, a random float value is generated between 0 and 360, representing the hue spectrum. This is passed through the HSV to RGB node to create a usable colour object by UE, and it's then applied to the point light colour and emissive material of the object itself. This is identical to how the random colours were generated for the lights in this post.
Below is a live embed of the blueprint I created (thanks blueprintue.com). You can interact with right-mouse drag and scrolling.
|Left Mouse Button||Select/Drag|
|Right Mouse Button||Pan|
This small experiment was particularly useful coming from a background where I'm familiar with the concept of objects and class-based programming. Understanding how to generate objects in Unreal Engine and control how they manifest themselves in the scene, as well as what points of data and behaviours are available, is incredibly useful and we'll definitely be building on this for future projects and pipelines.