Recently I released an asset called the Uniform Circle Spawner that allows users to spawn assets in a uniform circle which proved to be challenging. Originally I created the tool for personal use, but figured I could expand it to be something others could use as well. This meant I would need to test a lot of use-case scenarios to ensure the tool would work for everyone and had to make adjustments accordingly. On top of that it also had to be flexible and easy to understand and use, but ultimately it ended up being worth it in the end.
A Desire for Balance
So the big motivation behind creating such a tool came from wanting to compose a specific particle in Unreal. The initial idea was to have particle spawn in a uniform ring and then launch off at a target. I was fiddling around with several different spawn types in Unreal’s Niagara, but ultimately none of them could produce the outcome I wanted. The closest I could get was with the Cylinder spawner, but even then I couldn’t get them to spawn uniformly around the edge.
Obviously this is much less than ideal and doesn’t work with what I had in mind for the effect I want.
Seems like the issue was going to require a bit more problem solving and a bit of math to actually pull it off.
Thankfully while researching on how to approach this, I came across this useful thread that showed how to spawn actors evenly along the circumference of a circle. The basic premise is to give divide the number 360 (representing the circumference) by the number of points you want to spawn to get the degrees for each point. It then sets those points a distance (radius) from the center by using the forward vector of the spawner which is where the asset will spawn. The BP iterates through this by continuously multiplying the index of the point by the resulting degrees. I made a quick BP that basically spawned particles at the location of these points and ended up with this result.
There we go! A uniform shape to spawn actors! At this point I already had what I needed from it. Just needed to expose a couple variables for count and radius and it would easily fit a lot of basic compositions. However there was a useful opportunity here to expand it into something more.
The Circle of Opportunity
There was a good chance I wasn’t the only one who ran into this issue before, so I decided why not just expand it further to make it a basic tool that anyone can use!
There were many goals to hit in order to make a decent tool that people would actually use with as little frustration as possible, it needed to:
- Properly give the user feedback based on their inputs.
- Be easy to use and quick to adjust for rapid testing by the user.
- Be useful in multiple different scenarios and use cases.
- Be heavily tested in common use cases for bugs.
Seeing is Believing
So one of the most important goals to tackle and knock out right away is conveying the inputs and outputs of the tool. It’s critical that the outcome of the variables put in matches the output expectation of the user . Variables correlating with this would be the radius of the circle being made and the number of objects being spawned. This would prove easier than expected thanks to the Construction Graph and Visual Debugs found in blueprints.
Using Debug points we can have graphics represent variables and data in the editor and they’re fairly easy to setup too. All we have to do for the Debug Point is give it our spawn location to represent where our actors will spawn. For the radius of the circle I added some arrows to help provide additional visual clarity and make it easier to associate points with their origin spawner if multiple spawners are used.
With just a few simple adjustments to the blueprints the tool is already providing a lot more crucial feedback to the user allowing them to quickly adjust the properties and receive feedback in real time through the editor.
So for the composition I was constructing I wanted the systems to spawn all around one by one, in order to do this I simply had the actors spawn with a delay value in between spawns. With this method however it would help the user to know which point is the first actor to spawn and which one is the last. To do this it made sense to use a color lerp to make points that spawn first one color (green) and have the debug point colors lerp to the last spawn point which is represented with another color (red) as it gets closer to the last spawned object.
So with the color conveyance we can tell not only where the actors will start spawning, but also what general direction the actors will spawn in.
Shaping the Possibilities
With the conveyance sorted out of the way, it gives plenty of room to expand upon its functionality.
It already serves it’s purpose of being able to spawn assets in a circle, but what if it could spawn other shapes as well? It would definitely give the user more opportunities to create cool systems. So how does one approach doing that? Well it’s pretty simple, we give each point additional transform information that we can call in the BP and edit in editor!
In order to accomplish this we need to be able to pass additional transform data to each individual point. So this is where a struct becomes useful, with it we can create an array of struct that carries data that we can assign to each individual point. This allows the user to customize each individual point with additional information that exclusively affects that point and not any others in the spawner.
With this flexibility I decided to add along a few extra properties that would be nice customization bonuses such as “Spawn Point” and “Asset To Spawn” which I will cover later on.
Now with access to these properties in editor, users can offset the transforms of each point. To do this in the blueprint it’s as easy as just adding the SpawnOffset value to whatever transform location we already have for the points.
Now that transform offsets are setup, it’s possible to make a plethora of fun shapes!
Rounding Out the Features
With the inclusion of the struct, it allows us to easily add new properties to the individual points whenever we want and then all we’d have to do is set them up in the BP. As previously stated there are additional properties that were added that can be used to manipulate the spawner even further!
Take the Spawn Points established earlier, with the current BP setup it spawns actors in order based on the value set here. With this it’s possible to actually swap the spawn order of the points!
So by reorganizing the spawn point orders as seen in the top right picture, the particles can be spawned in a completely different order than just clockwise or counter clockwise.
The “SpawnedAsset” parameter was pretty straight forward, it just overrides the asset to spawn if the “CustomSpawnProperties” boolean is checked, otherwise it just spawns a default asset set in the inspector. It allows each individual point to spawn completely different assets.
Overall this was a very fun tool to create and experiment with and I’m looking forward to seeing what kind of compositions will be creates using this tool and I am looking forward to further expanding it.
So what’s in the future for the asset now that’s it officially released? Well now that a lot of common use scenarios have been covered, there’s more room to add more experimental features such as:
- Lines generating between points.
- Points spiraling outward to create spiral shapes and patterns
- Add the ability to have one spawn in the center
If you want to figure out how to use the Uniform Circle Spawner in your project and also how to use its features, check out the tutorial below.