4

I'd like users to be able to design their own GameObjects in unity, and somehow import them at runtime into a game I'm making.

That means maintaining the hierarchy (there may be child objects), and any scripts, components, models, and materials used.

After looking around, I haven't seen any cookie-cutter solutions to this problem, but I also have a hard time believing I'm the first person to attempt to write a moddable game with Unity's engine. Are there any best practices for adding prefabs/assets at runtime?

Brent Allard
  • 386
  • 5
  • 20
  • 1
    I doubt you'll find any "cookie-cutter solutions" to such a task, if I'm honest. Allowing the use of mods, is an entirely new ball-game. Models etc, this is easy enough, designate a directory, and simply load anything that's in there. But allowing custom code, will require extra efforts, such as external support for scripting engines etc, such as Lua. – laminatefish Aug 17 '17 at 13:07
  • @LokiSinclair I've seen examples of C# being compiled dynamically before, so I'm hoping I don't have to turn to Lua or something similar! – Brent Allard Aug 17 '17 at 13:19
  • Well, I'm sure you could, but for maximum exposure a scripting language offers a lot more benefits. I personally wouldn't limit a project to compilation only. There are already a few Lua assets for unity, then you just expose content for people to use. – laminatefish Aug 18 '17 at 10:36

1 Answers1

1

AssetBundles are the way to go.

Basically you can create one or multiple assetbundle files from scenes or specific objects which pack everything into them.

Assetbundles contain everything you want, except new scripts. You can reference scripts but not create them per default.

If you want to bundle new scripts you need to create a ddl file and load that during runtime.

Lyze
  • 385
  • 1
  • 4
  • 11