Feb 272020
 

I’ve published my first asset on the Unity Asset Store! Find it for free here: https://assetstore.unity.com/packages/tools/utilities/fence-layout-tool-162856

Or get the code directly from GitHub: https://github.com/AndyFenwick/FenceLayout

[EDIT: If anyone is interested, it’s had 142 downloads in the first five weeks after release. 29 in the first three days but it’s steadily getting a few each day since. That’s actually more than I was expecting.]

Fences

While making the Frozen game I wanted to put some fences down and assumed there would be a simple script on the asset store for this. There were a few fence tools available but they were all paid for. I’ve bought a bunch of art assets and tools (modelling definitely isn’t my strong point), but writing a simple tool to put a few objects in a line seemed like a perfect learning opportunity!

Here’s the tutorial video if you want to see what it does:

Writing the actual layout script was mostly simple. Add the prefabs, set up spacing, scaling and offsets, sample the terrain height and plop the prefabs down between the waypoints.

The only non-trivial part was dealing with uneven ground. On mostly flat ground the fences all line up nicely and look good. However on sloped terrain their disjointed and partially underground. The solution is to shear the fence model in Y so that both ends are on the ground. The only problem here is that Unity transforms don’t directly support shear. However there is a workaround by using two parent transforms and a series of rotations and non-linear scales. See this: https://answers.unity.com/questions/961330/shear-transformation-using-gameobject-transformati.html

I implemented that and it works well, with nice curving fences:

I’m not sure what happens to the colliders – the debug rendering becomes detached somewhat from the geometry, but it’s close enough that it works in my game so I’ve not investigated further.

Custom editor

The most fiddly bit was getting the custom editor and inspector working nicely in Unity. The input handling / selection handling stuff is pretty confusing – controls either wouldn’t consume input events, or they’d consume too many events and it would be impossible to select anything else. After some experimentation, this setup seems to work:

void InputUpdate(SceneView sceneview)
{
	Event e = Event.current;
	int controlID = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive);

	if (e.control)
	{
		HandleUtility.AddDefaultControl(controlID);
	}

	if (e.type != EventType.Repaint && e.type != EventType.Layout)
	{
		GameObject fenceObj = Selection.activeObject as GameObject;
		if (fenceObj)
		{
			FenceLayout fence = fenceObj.GetComponent<FenceLayout>();

			// Do things with the fence...
		}
	}
}

public void OnEnable()
{
	SceneView.duringSceneGui += InputUpdate;
}

public void OnDisable()
{
	SceneView.duringSceneGui -= InputUpdate;
}

I also had various bugs with things not saving until I found out you have to manually set the object as dirty:

EditorUtility.SetDirty(m_fenceLayout);

And then found that editing a prefab still wasn’t saving. The fix for that was to mark the whole scene dirty if anything has changed:

if (EditorGUI.EndChangeCheck())
{
	EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
}

Have a look at the full code on GitHub to see the specifics.

Admin

I hadn’t quite realised the amount of admin that’s required to get something on the asset store. We publish enough apps in my day-job, but when you just want to publish a simple script it’s a bit of work to make (and work out what to put on) the required thumbnails, screenshots, social media banners etc. Plus write the documentation, record a tutorial video, write descriptions and all that. Good learning experience though.

Feb 162020
 

I bought a bunch of the popular Unity landscape tools recently, namely Gaia Pro, Vegetation Studio Pro, Complete Terrain Shader and River Auto Material. I also picked up a couple of the Nature Manufacture asset packs.

Here’s a little video of using the tools to quickly create a landscape. Note that I have spent a decent amount of time setting up the biomes and rules first so there’s work to be done after acquiring the tools, but once that’s done it’s super quick to create landscapes!

Gaia Pro

Gaia Pro from Procedural Worlds is primarily a tool for creating terrain heightmaps. It includes a wide range of ‘stamps’ (predefined heightmaps) which you can move, scale and rotate, and then apply to your terrain. There are loads of modes for applying stamps – add, subtract, blend, or apply effects like erosion, steps or peak enhancement. Stamps can be further combined with distance masks or other heightmaps for plenty of control. There’s a nice preview visualiser so you can see more or less what it’s going to do to your terrain before you apply.

Gaia Pro has loads of other features bundled in. You can set up texturing rules based on angle and height to automatically texture your terrain, as well as add rule-based spawners to add trees, rocks and buildings. Also bundled in are other asset sample, such as water, environmental audio, post-processing control, and a selection of trees, rocks and building assets.

This was the first tool I bought, and it’s a good all-in-one package to get started with. The terrain editing bit is great, but personally I don’t used the texturing and spawning controls – I find that Vegetation Studio Pro does that better.

Vegetation Studio Pro

Vegetation Studio Pro from Awesome Technologies is a must-have if you’re making large outdoor terrains. It takes a bit of setup, but afterwards you can author whole terrains in minutes.

You set up a series of biomes, each of which consists of terrain texturing rules and vegetation placement rules. The terrain texturing is similar to Gaia. You defines rules for each texture based on height and slope, convex or concave terrain, and Perlin noise, and they’re all combined to get the final texture. Vegetation follows similar rules – drop in your prefabs and set up similar rules for each based on height and slope, underlying texture, and density.

One massive bonus of the Pro version is that it supports multiple biomes types simultaneously. You define a default biome and can then drop other biomes into the scene and define their extents. The highest priority biome at each point is the one used, and there are cross-fade rules and curves to blend textures and reduce vegetation density or scale across the border.

In my game I have a default grass biome. I’ve defined a couple of different forest biomes so I can drop them into the level, mark the borders and you’ve got instant forests. And it uses its own batching and rending system so everything draws super fast! It’s the most expensive tool I’ve bought but definitely worth it.

Complete Terrain Shader (CTS)

Complete Terrain Shader is also from Procedural Worlds. It replaces the default Unity terrain shader with a more advanced one with more options. I think it has two main uses – the simple one is to add interest to distant terrain and break up the tiling, and the second is to use height maps for each terrain textures to completely change how textures are blended together.

The standard shader variant adds ambient occlusion, low frequency detail normal maps, height-based geological banding and snow, lower frequency tiling on distant terrain, and a few other features. These tweaks will make your distant terrain more visually interesting and less flat. Whether it’s worth it probably depends how much stuff you have in your world – if there’s a lot of detail and objects over your distant terrain it might not be so noticeable.

There’s an advanced shader variant that uses per-texture heightmaps, combined with the standard texture blending, to determine which texture to use per-pixel. I’ve not looked into this too far, but done well it can give far higher resolution, sharper texture blending.

River Auto Material (R.A.M.)

River Auto Material is a tool for creating river, lake and road geometry. You just click to add river spline nodes, set the scale and rotation of each node, apply a material preset, and paint transparency for blending. Fast and slow water effects are applied automatically based on the river gradient, or you can paint them yourself.

You can also simulate river flow, which I use a lot. Drop in the start point, hit the Simulate button and it’ll generate a river that flows downhill. Then there’s a terrain carving tool – draw the river bed profile in the graph editor, hit the Carve button and it’ll reshape the terrain around the river and blend it in to the existing terrain.

The other great feature is Vegetation Studio Pro integration. For each river preset you can define an associate biome type. Simply set the desired biome width, press a button and it’ll automatically generate a matching biome mask around your river. This makes it really easy to blend your rivers into your scene – the sand and rocks in the screenshot above were added like this.

I’ve not dived too far into the possibilities yet, but it’s a fun tool to use and I like the results a lot.

Feb 092020
 

It’s been a while. Turns out that having a child takes up a lot of your free time. Who knew.

It’s a tricky balancing act with children and technology. Too much screen time is bad, but they need to learn to use technology and feel comfortable with it. Being from a tech background, I often wonder if we were more conscious of this and a bit too strict (somewhat hypocritically, thinking back to my own youth…).

Everything is touch screens these days. Direct control is so much easier than indirect control, so I wanted to make sure that my daughter had some practice with a controller. Time to get back to Unity and make something!

I did a couple of simple 2D games early on (I’ll share them later), but I wanted to try something in 3D. My daughter loves Disney and Frozen, and after a quick Google I found some passable Elsa and Anna models (3D modelling is definitely not in my skill-set). After a quick proof of concept and a bit of research, the Unity Black Friday sale was upon me and I went all-in with a bunch of the popular tools. I may follow up with a technical post later.

The only slight hiccup is that we have another child due any time now, and nothing is going to get done for a few months afterwards. So this is what I’ve come up with so far:

There’s no real gameplay there, but my daughter always prefers to play in a sandbox than be told what to do, so running around and exploring is fine. You can summon snowmen, push them around, throw snowballs at things and cast magic at wolves to scare them off. I could spend hours more detailing the world and adding areas things (there’s loads of black areas), but I think it looks pretty cool so far.

Obviously the game will never be finished or distributed as they’re not my characters, but it also has the advantage that it only has to run well on my own beefy gaming PC so I don’t have to waste limited time on performance and optimisation!

Games for kids

Thinking about games for children in general, every child is so different that it’s really hard to find anything ideal off-the-shelf. They’re either too complex, or too simple, or require reading skills, or the theme isn’t interesting. Which is why I just make my own games, which can become more complex as my daughter grows up. And most importantly she can see how things are made and give ideas and suggestions about what to add, and see me make changes in real-time. Much better than games being some mysterious black box (I realise I’m lucky in being able to do this). If my kids are going to be gamers, they might as well start with early-access, moddable PC gaming! Much closer to the Spectrum scene I grew up with.

Co-op modes

Co-op mode is the best thing ever in gaming. It’s the ideal way to share a game with your family, and done well it can let an adult handle the complicated bits while the child does what they can.

This fit really naturally with a Frozen game, with two main characters. It’s not really in the video (because I recorded it myself and using two pads at once is hard) but one pad controls Elsa, and one controls Anna. Both pads can control the camera, so the child doesn’t have to. If there’s no input on a pad for five seconds, that player drops back to AI mode (they just follow you around for now) and the camera focuses on the active player. Any input will put them back under player control and the camera will keep them both in view. No rules around this, no complicated explicit join/drop-out mechanics, it ‘just works’. I’ll definitely be keeping this concept for future games.