Unreal Engine – Array Blueprint
Below is a simple array blueprint that you could use to create a random sequence of colours from a point light.
Simple Array Blueprint
The blueprint actor detailed in this post will allow for your character to cycle through random colors in a point light. This tutorial does require some basic understanding of blueprints
Create Blueprint Actor:
- Right click in a folder – Create a Blueprint and Select the ‘Actor’ Blueprint.
- Name accordingly.
- In the components section add:
- A point light.
- A static mesh (this can be a lamp or light fitting).
- Box Collison.
- Position these so they fit your requirements. Make sure your character can stand inside the trigger box.
- See Example below.
- In the Event Graph add the code below (Enable and Disable input and Get Player controller) to activate the player controller.
- To add the On Component Begin Overlap node – Right Click on the Box Collision in the components tab- Select: Add Event – On Component Begin Overlap
2. Add a variable – Change it from a Boolean to a Color Actor Variable (to do this click on the default bool variable that has been added and search for color).
3. Right Click once over the Color name to convert it to an Array.
3.1 Select the Color variable and in the right hand side details panel – add 3 array elements (which will only be colors).
3.2 Change these to different colors of your choice.
4. Drag in the Color array variable into the event graph.
5. Drag off from its only socket and search for ‘Get (a copy)’
6. Now right click in the graph and search for Random Integer.
6.1. Add 3 into the field of the Random Integer as we have 3 colors in our array (this could be higher if you use more than 3 colors)
7. Plug this into the ‘Get (a copy)’ node.
8. Drag in the point light from the components section – Drag off and search for ‘Set Light Color’
9. Plug in the ‘Get (a copy)’ node into New light Color socket.
10. Search for a keyboard key letter or number (e.g. E).
11. Plug this into the ‘Set Light Color’
12. Done! Now when the player character enters the collision box and presses E – the light color will change randomly to one of the inputted colors.
The Final Graph should look like the below:
If you have any questions please do get in touch or leave a comment. Thanks!
Pro Tip: Use an Interface that connects your character to any interact actions that take place through out the game/simulation. This has many advantages, as you will not need to keep adding the enable and disable input nodes and only need to add one interface node to your blueprint.
You also will be able to update the interface that will in turn update all blueprints using the interact interface.
For example see below the same code but with an interface used instead. I will create 2 or 3 posts on how to create and use an interface at some point in the near future. Please leave a comment if you would like to see these posts sooner.
Also please check the Blueprints page for further tutorials on Blueprints.