Avatar

cheeseburger-inhaling yank

@nihilocrat / nihilocrat.tumblr.com

I make games about pushing sharp things into soft things that scream and bleed until they stop moving.
Avatar
reblogged
Avatar
skyroguegame

SKY ROGUE RELEASED ON THE NINTENDO SWITCH!

The Switch version includes exclusive DANGER ZONE motion controls! Use the right Joy-Con as a flight stick and the left Joy-Con as a throttle!

During launch week, the PC version of the game will also be on sale for 40% off!

Avatar

Mod Support in Unity

I wrote this for Ben Porter’s fun #NotGDC “event” on Twitter. I’m taking a year off from GDC but got ALL JELLY reading THE TWETS about people saying smart things at GDC. If you’re wondering how I have any authority to talk about this subject, look no further than the Sky Rogue Steam Workshop!

Let's get this out of the way: adding mod support to your Unity game is a fucking chore.

In most games, with most engines, to modify game files you need to do the following:

  • Find the archive(s) containing game assets (this might not even be necessary)
  • Edit the assets
  • Replace the pre-existing archive(s), or if the game supports it, tell it to load yours instead of the main ones

This is not really possible in Unity, unfortunately. Why is that?

  • The tools to do this are scarce; here are ones I've found:
https://7daystodie.com/forums/showthread.php?22675-Unity-Assets-Bundle-Extractor
http://zenhax.com/viewtopic.php?t=36
  • The assets they extract are highly optimized assets for particular platforms, which are often not easily editable

So in the end, you need to add modding support yourself. Bizarrely, there is nothing on the asset store directly related to doing this for you. I SHOULD PROBABLY DO SOMETHING ABOUT THAT, SHOULDN’T I?

There are currently two dominant ways of adding this support to your game. Like with everything, each has pros and cons.

Roll your own asset management system (load assets directly from disk)

Pros:

  • It works exactly how you write it
  • Unless you really make a mess of it, it should be the easiest for modders to use. You might not even have to write documentation!

Cons:

  • You have to write it all yourself
  • This means asset importers: mesh importers, texture importers, sound, script, everything
  • You have to write your own editor, or hope your modders are okay fiddling around with text files
  • Modders will be restricted by the boundaries you give them. Expanding those boundaries will always require more work on your part.

Use Asset Bundles

Pros:

  • You don't have to write your own importers!
  • You don't have to write your own editor!

Cons:

  • Your modders have to learn how to use Unity; from personal experience many are intimidated by it
  • You need to either write your own "glue" code or share practically all of your code
  • Sometimes they just don't work and I still haven’t figured out why
  • I can count the number of games doing this on one hand. Google will probably not help you when you need it.

ROLLING YOUR OWN

If you want to go this path, you should start doing it the moment you start making your game.

Unity has a few tools for importing assets from disk; they don't really seem intended for this but they work just fine.

Beyond that, it's not hard to find an .OBJ importer for Unity; there are several to choose from. Some are slow. Some don't seem to work with all .OBJs.

You can use JSON, XML, or YAML for "gameplay" assets; several libraries exist for C#. You will not be able to serialize anything but basic types like int, string, and lists, and might have trouble saving and loading highly nested objects.

With these you can get started with your mod support. To reduce the amount of friction between the mod assets and Unity itself, you should probably make your own parallel GameObject / Component system which will save basic transform data and hierarchies, along with the components on an object and their values. You'll need to lean heavily on C#'s reflection abilities for this. If you really want to go "whole hog", I would advise that you implement your own game assets with this system, not only to let modders make total conversions for the game, but also to constantly test the system and expand it as you need more functionality from it, simultaneously adding features for your modders.

ASSET BUNDLES

You’ll want to download the Asset Bundle Manager from the Asset Store (

) before you get started, unfortunately it was released before I started adding my own mod support, and is intended to be used with a newer asset bundle API which I haven’t yet upgraded to, so I can’t give any specific advice or tutorials for it.

You get a LOT of things free following this path because your modders are using Unity itself to make the mods and the bundles they export are supported by Unity out-of-the-box. I’ve found it easier for modders if you distribute your SDK as a Unity project directory and not as a .unitypackage, something that they can open in Unity and get started right away with. The extra complexity of Unity itself means you’ll need to actually write documentation, with screenshots, to make it easier for more people to mod your game.

However, you’ve got to create and distribute an “SDK” for your modders to load in Unity to create these bundles. You've got to share your scripts and potentially the source files of other game assets. I would like to point out that this is probably not as bad as it sounds; I doubt anyone would clone your entire game and sell it but I also don't want to be proven wrong. You can build all of your scripts into a .DLL, but without extra obfuscation, a decompiled C# .DLL is practically the same as the source code, without comments and whitespace.

There's a middle ground, but it makes your support a bit more complicated: Write a bunch of "empty" versions of your game scripts, just the ones which modders need to use to create their assets. By "empty" I mean they lack all of the functions and just have the public variables which get serialized by Unity and appear in the inspector. You'll need to write some glue code to convert the "empty" versions of components into real ones when you load in the bundles; use C#’s reflection to read from one component and write to the other.

If you want to support users writing their own C# scripts, you’ll need to do a little extra work, but thankfully Unity has documented that:

However, to actually let modders do things that operate with the scripts built into your game, you’ll need to either include those scripts in your SDK or create an API to do that; no small feat. I don’t have any personal experience doing this yet, but Cities: Skylines has such an API and you may be able to figure out what they’re doing by taking a look at their documentation:

This is still a topic I’m actively developing things for, and I’ve been talking to other devs the whole time so this isn’t comprehensive at all, but I hope it gives you a good starting point. As a bonus, here’s some reasons why you might want to add modding support at all:

  • Mods add a lot of value to your game. If you have a heavily system-driven, simulationist, or sandbox game, mods practically create several sub-games for you. I bought the original Half-Life specifically so I could play the Counter-Strike mod (before it was a standalone game); this could become true for your game as well.
  • Mods grow your community. It gives players a path for becoming heavily invested in the game and add a little bit of themselves to the game. More investment means they talk about the game more, then people get invested in the mods themselves and talk about those. People talking about your game is what makes up your community.
  • Mods let you add licensed content to your game, by proxy, and not get sued. The Arwing from Star Fox looks pretty fitting in Sky Rogue. So does the Swordfish II from Cowboy Bebop. I couldn’t add either of these myself to the base game, and I’m really glad other people have. It sounds trite, but I’ve heard of players specifically buying the game because of these particular mods.
  • You can just dip your toe in and make some minor commitments for gains which can mean a lot: Guacamelee lets you customize the player avatar but nothing else.  The Long Dark crowdsources its localization by implementing each language as a community-created mod.
  • Modders will surprise you. They will make things you didn’t know were possible in your game. They will break your design and make stuff that’s cooler than you would have made because you’re in too deep. A bomber that can drop 100 bombs at once is broken as hell if you make it. If a modder makes it, it’s silly and fun and awesome.
Avatar
reblogged
Avatar
01010111

Hey! I’m gonna be at the Richmond Zine Fest this Saturday with RVA Game Jams! I made this zine to try and help people who want to make games psyche themselves up and make games!

You are using an unsupported browser and things might not work as intended. Please make sure you're using the latest version of Chrome, Firefox, Safari, or Edge.