Arrays are a collection of variables of the same type. Say you had an array of integers called myArray. It could be 4,3,6,2,0,6,1,5. The array’s length would be 8. But be careful – Arrays start at 0. myArray[0] = 4. myArray[2]=6 and so on. In Unreal you can have arrays of anything from materials to actor blueprints to text.
Here is a very good tutorial on it if you need more info.
Today we’ll use arrays for two things. 1) We’ll give our Kristina character a random color at start up and 2) We’ll make a trigger that says random words of encouragement to Kristina. Everything is updated on the gitHub.
In the BeginPlay event in our character blueprint (Kristina) I made an array of three materials and then set the material to choose a random one from my array.
Next to make my random talker widget I made a RandomThingToSay array, wrote three things in there and then on the Construct event set a CurrentThingToSay text variable to take a random slot from the array.
Then I bound the text in the widget to the CurrentThingToSay variable.
In the actor blueprint I set up a box collision to add and remove the widget to the screen.
