In my professional work we have this awesome web-based Content Management System. In my indie project I do not have this so went about building a similar system directly in Unity using the power of Scriptable Objects. I am making a JRPG at the moment and that needs a lot of content so makes sense right?
Scriptable Objects are an underused gem in Unity and are a great way of storing data. Let’s look at this example:
Here I have a battle character in a scriptable object. I have built a system where I can use Animation Curves to define stats per level RPG Maker style and set up what ability is available at what elvel and all that other fun stuff.
In fact, I have a whole load of similar scriptable objects that hold all my data.
The neat thing I can do here is put these Scriptable Objects into asset bundles
And build them into my Streaming Assets
Now I can upload my asset bundles to Google Cloud, Amazon or Azure and download them when I need.
In order to make my awesome JRPG I needed some sort of Tile System to create awesome maps. I have some code to load data from Tiled, however, Unity recently added their own system and doing it in the editor itself is much cleaner in my opinion than doing it in an external tool. However, apart from the Manual, there are not a lot of tutorials on how to use it and I found the manual pretty sparse.
The way I wanted to do it is the way I had previously set out with Tiled:
Essentially I wanted there to be 3 layers. Background, Middle and Foreground. However, the docs were not great in showing a way to do that, and inevitably you were not able to set a layer per tile like I had been doing in the past when loading from Tiled. So looking back at Tiled itself, I realised the layers were actually 3 tilemaps. The solution in Unity; create 3 Tilemap objects
By creating 3 maps and then using the sorting layer to decide the draw order I could essentially have 3 layers like I did previously.
Similarly, as the player character only interacts with the middle layer, I only needed the physics object to be on the middle layer gameobject.
The last thing that did catch me out, and is a bit of a pain is having to go through is setting up if the tile is “Walkable” or not.
You essentially have to go to each individual tile asset and select the collider type. Which makes sense to be fair.
There are a load of awesome brushes as well you can grab from here:
Which includes placing Prefabs and Animated Tiles. You do need to grab the Beta of Unity though which is less than ideal.
This little trick is from something that I worked on that involved robots. So I added the Robot from Infinite Warfare (a game which I have, but need to actually finish… like all my other games!). Essentially there was a character that moved around an environment and attacked enemies. The problem was he sometimes got obscured by the environment. As it was a prototype, I made the quickest and dirtiest thing I could and whacked it in.
As the diagram shows above I raycasted from the camer to the player character. If the raycast hits anything marked “Obstacle” or equivalent term the object is deactivated.
This is SUPPPEEERRR basic. There are some cleverer things you can do like do a box cast and seeing how much an object is inside the box cast and fade it out, but if you need to get somehting up and running quickly then this is a quick and dirty implementation.