Flocking Behaviour System Plugin for UE4.20+
Flocking Behaviour System is a tool to quickly and easily add multiple flocks of entities into a scene to simulate the flocking behaviour.
Available on the Unreal Marketplace
Standard Flocking
Once you've installed the Flocking Behaviour System plugin into the engine, and you've enabled it, we can begin using this in your project.
Let's start by adding a flock actor into the scene. Go to the modes tab, and search for 'flock', then drag it into the scene, like this.
Go ahead and press play! They will start to flock!
Let's change the settings around! We have 3 categories of settings, 'Boid settings', 'Spawn Settings' and 'Flock Settings'.
Boid Settings is where we can customize each boid's attribute, like the mesh, the size, the rotation, movement and perception radius. Also, the limits of how far the boid can wander off.
Spawn Settings is where we can specify the spawn parameters, like the number of boids we want to spawn in this flock and the spawning radius. This is the area that the boids will get randomly placed in, on Begin Play.
Flock Settings is where we can customize each behaviour rule to give a different flocking result. We can randomize all the forces on Begin Play to see drastically different behaviours. Alternatively, you can edit each force to your liking. Changing each force will affect flocking. We can also enable goal-seeking for this particular flock and choose a goal actor in the scene to move towards. We'll set up goal-seeking later.
We can increase each boids' perception radius so they can easily see each other and flock together more easily
Perception Radius: 1000 (Highest setting)
Perception Radius: 100 (Lowest setting)
We can change the mesh of the boid to give a different look, for example, fish!
The number of boids that can spawn can be changed, the max boids per flock are 400.
The spawn radius is the radius in which the boids will randomly be placed in when spawning.
Small spawn radius: 500
Large spawn radius: 2000
Next, the flocking settings. We can choose to randomize all forces to begin to play or tweak the forces ourselves. Below are some examples.
Alignment: 2, Cohesion: 1, Separation: 5 (strong separation)
Alignment: 1, Cohesion: 3, Separation: 2 (strong cohesion)
Alignment: 8, Cohesion: 4, Separation: 9 (strong alignment and separation)
Multiple Flocks
Now, on to goal-seeking and path-following!
Goal Seeking
Search for Goal from the Modes tab and then drag n' drop into the scene, like this:
Select a flock actor and assign the goal actor to the goal reference in Flock Settings. Make sure Enable Goal Seeking is enabled.
When you press play, the entire flock should seek towards the goal! Let me explain the settings of the Goal actor if you want to tweak it a bit.
We have 2 categories, Settings and Debug
Settings category:
Acceptance Radius: The radius in which the goal will accept that it has been reached. If the distance from the boid to the goal is 200 units away and the acceptance radius is 100 units, the flock will only need to travel another 100 units to reach the goal, and the goal actor will accept that it has been reached.
Randomly Generate Goal Locations: Should we randomly generate a new goal location, when the goal has been reached?
Range: The bounds of the box that a new goal location can be placed in. (Enabled when Randomly Generate Goal Locations is enabled)
Start at Custom Location: Should we start at a custom location, in world space? (Enabled when Randomly Generate Goal Locations is enabled)
Start Location: The custom start location/origin of this goal actor. (Enabled when Start at Custom Location is enabled)
Spawn New Point when Adding to Array: If true, when adding a new element to the Goal Locations array, spawn a new point.
Goal Locations: A list of pre-determined locations for the boids to move to.
Debug category:
Show Acceptance Radius: Display the acceptance radius?
Show Path: Show all of the connected points in the Goal Locations array?
Show Range Extent: Show the bounds of the range box, when Randomly Generate Goal Locations is true.
Show All Points: Display all the point sprites connected to this goal? (Image below)
To add a point, click the + icon in the Goal Locations property
Then, drag a point actor from the Modes tab
Assign it to the array, like this
To see the connection, tick Show Path in Debug category.
Repeat for as many points you'd like to have connected.
The result:
I need help!
If you are still having issues getting this plugin to work, feel free to join the Discord Support Server and report what the issue is in the #flocking-system channel.