Asset Review: TypeSafe - Resource Constants

Enter Unity:

You have some programming experience, and the inspector's drag-and-drop features just make development so fast.

You make a couple of games this way, but notice some organization problems in your last one.

You'd rather just finish and release though.

3 years later, you're developing a full-scale video game.

3 months into development, you notice a stringy mess of drag-and-drop references!

"There has to be a better way than dragging these asset references to EVERY GameObject and Prefab!"

Well there is, and it's called TypeSafe.

What Does It Do?

TypeSafe is a Unity Asset that allows you to generate references to your Resources as constants in your code.

That means to reference Layers, Tags, Prefabs, and some others, you won't have to drag anything or create constants by hand.

Pretty awesome. Here's an example:

var playerLayer = SRLayers.Player

Okay, so we have a reference to the layer assigned to Player objects. Now, I don't have to record it as a constant string anywhere because TypeSafe already did that automatically.

Let's say for example we wanted our player not to be able to shoot themselves. We could do something like this:

Physics.IgnoreLayerCollision(SRLayers.Player, SRLayers.PlayerProjectile)


"Okay, so I don't have to type layer names in my scripts. Big whoop, I'd rather keep my 10 bucks."

...but wait, there's more!

So TypeSafe also stores references to everything in the Resources folder. What's more is that each folder is a class, which allows for great code readability.

For example, let's say I have 3 different enemies I want to reference. They're in my Resources/Prefabs/Enemies/ folder. Here we go:

enemy1 = SRResources.Prefabs.Enemies.Gunship

enemy2 = SRResources.Prefabs.Enemies.Interceptor

enemy3 = SRResources.Prefabs.Enemies.Frigate

Naturally they're spaceships because this is an Omnirift post.

Anyway, I have references to my enemies prefabs and I can now spawn them in the game or do anything else I'd like with them.

But what if you wanted to spawn all of them in a loop? Check it out:

foreach (GameObject enemy in SRResources.Prefabs.Enemies.GetContents<GameObject>()) {

// do something with enemy


Oh look, I didn't have to drag my 3 enemy prefabs into a Singleton Unity GameObject's collection with the inspector and iterate over it. This is why TypeSafe is really great.


I'll be honest, this asset gives some addition to the infamous 'Unity Refresh' when refocusing Unity in your OS after file/code changes.

That's why in TypeSafe's settings menu, you can choose either automatic rebuilds or manual builds.