For our next game, I have been experimenting with an idea to have XML elements - loaded at game startup - dictate which Unity components get attached to instantiated game objects during initialization. I also wanted us to have some level of control in the Unity inspector over which scripts are actually used for the components.

Consider the following code:


This adds MyAwesomeScript as a component on the current gameObject. Simple and straightforward (and probably how you would add components in code 95% of the time).

But what if you didn't know MyAwesomeScript at compile time? What if the type of component that's actually added isn't even known until you call AddComponent()?

In comes MonoScript to the rescue! The MonoScript class is a Unity C# class that defines a type of script, not an actual instantiated script object.

As an example, imagine the above component that's added is actually configurable by the inspector in Unity:

Then when AddComponent() is called, it would use whatever script was set in that field (MyAwesomeScript in the example above).

Later if some designer or engineer wants to experiment with a different component script called "MyOTHERAwesomeScript", they could just change that value in the inspector:

and it would *just work* without having to modify the code. Of course if any other scripts are referencing functions in "MyAwesomeScript", you will need to ensure that "MyOTHERAwesomeScript" implements the same functions! Using interfaces will help out a lot here, but I will leave interface discussion until a later tech tip :-)

But the problem is how do we actually reference that script type in code when calling AddComponent()? In the code snippet above where I first called AddComponent(), we had to know the type was "MyAwesomeScript".

This is where MonoScript comes in. The above inspector items are actually coded as:

public UnityEditor.MonoScript ScriptToAddAsComponent;

MonoScript is essentially an object representing a class type, not the class itself.

When we call AddComponent(), we can do the following:

// Assume ScriptToAddAsComponent is the name of the inspector field.
System.Type classType = ScriptToAddAsComponent.GetClass();

And voila! Whichever script is set in the inspector gets added as a component. The System.Type is a C# thing, and fortunately Unity has an AddComponent() overload which accepts a System.Type (see here for the Unity documentation on AddComponent() - note I use the full "System.Type" qualification in my code example, but if you just use the System namespace in your script then you don't need to use "System." before "Type").

Okay, thought that was interesting enough to share!

Follow @AngryGoatGames on Twitter! We post useful game dev articles as we come across them!


20 views0 comments

Over the past week we have been hard at work on a prototype for our new game! We were able to get more models created for the game and we were also able to get some selection UI for terrain and items!


Pumpkin Running Animation

Before this week we had a floating character, so we decided to give her a running animation!

We are trying to maintain a bouncy aesthetic with Pumpkin as she is supposed to be cute and bubbly. Next we will need to add a few idle animations to give her an even more natural look! Stay tuned!


Terrain Effects

We were tired of staring at the same checkerboard pattern for the terrain so we decided to go ahead and add a terrain texture. It's amazing how much this adds to the overall "feeling" of the game. It looks more like a game world instead of a construction zone.

Before... booooring

After! A real world!


Plants so far

We've modeled some of the more common plants, such as vegetables and trees. Below is our progress!



We also worked on the selection mechanism. This one was a bit tricky since we had to use different methods for the terrain selections and the item selections. Below is a video highlighting what we have done so far:

For the terrain selection, I created a custom terrain shader that had material properties to set which UV coordinates correspond to the selection minimum and maximum bounds. The shader was written to draw a color within this region, and then softly fall-off on the edges. I may write a more thorough tutorial of this later. It was extremely helpful to download the standard terrain shaders from Unity as a template.

For object selection, I found the wonderful asset "Quick Outline" by Chris Nolet:

Best of all, it's free! And that's a great price.


That's all for this week, folks! Have a great Christmas and a Happy New Year! We will take a break from posting devlogs for the New Year week. But we will definitely be tweeting, so follow us at @AngryGoatGames!

13 views0 comments

Lots of stuff this week! Some sneak peeks into our upcoming 2021 game, some praise for the fun game we played for #FeedbackFriday, and some business-y updates.


Cartoon Modeling in Blender

We've been hard at work creating starter assets to work with in our upcoming game. As mentioned on our Twitter page, the art style of our new game will be cartoony and cute!

To get the soft, rounded look to fit the aesthetic we're going for, we made extensive use of several tools in Blender, such as the Skin and Subdivision modifiers, as well as Bezier curves. The result is as follows, the beginnings of our new game:

Follow us for updates about this project! @AngryGoatGames


#FeedbackFriday Game: Crooks Like Us

This is one of the funnest games we've played! We were very impressed! It was fun, casual, light-hearted, and hilarious - it would make a great party game!

You can steal the guard...

...and the secretary! Everything and everyone is fair game to this dastardly villain!

10/10! Check out @outoftunegames's game here:


Business-y Stuff

This week is a great milestone for us. For one, Angry Goat Games is officially open for business! The government gave us the thumbs up, and we're an LLC now! This is an exciting time for us ^_^

Also, Snavi is coming out to Android! We're just waiting on the ok from Google :-) We're excited for more people to be able to play our game!


That's all, gang! Make sure to follow us on Twitter: @AngryGoatGames We post game updates and gamedev stuff!

34 views0 comments
No tags yet.