Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Modding Software using Unity

Discussion in 'General Discussion' started by Arylos, Jul 16, 2017.

  1. Arylos

    Arylos

    Joined:
    Feb 23, 2017
    Posts:
    3
    I'm posting this in the right forum, but I could never really find good answers for some basic things. I'm creating a 2D platforming game using Unity and one thing I want to do is create a level editor either within the game itself or standalone so players can create their own levels and host them on the Steam Workshop. I'm pretty sure how to do it myself or at least how to make it in concept and everything's good to go. My main question is that either in the game or as a standalone software (probably made in Unity itself for convenience), how can I create a scene file that I can be created within this program that can then be exported and placed into the game? (There will be no coding for now for security)

    One fix I thought of was creating a Unity package modders could use, but that would leave a lot of code exposed including Steam API so I'd rather not do it that way. Basically, can a scene inside a game or editor be saved the way it is at run time and then exported to a select location? If not, what could I do to make it work or any ideas I might have missed?
     
  2. cyberpunk

    cyberpunk

    Joined:
    Mar 20, 2013
    Posts:
    226
    You can save to a Unity scene directly (at least it seems that way, I've never tried). See the manual here:
    https://docs.unity3d.com/Manual/YAMLSceneExample.html

    However, it may be easier (and more flexible) to design your own custom level format for your game.
     
  3. Arylos

    Arylos

    Joined:
    Feb 23, 2017
    Posts:
    3
    Good to know. I've also seen a lot of threads also saying it's possible, but not straightforward. I know that if I commit the time to create it, it will consume a lot of development time, but it would probably be better to do it early so that way I can build the rest of the game around it. I'm on vacation right now so it will be some time before I get around to actually testing it and seeing what works.

    The second option might be more doable. As in a blank level format that players fill in with their ideas? It will still be hard without the ideas being sent to me and me having to build them and ship them in an update unless I setup the Workshop, but that should give the players a way to test it themselves somehow. Still trying to fine-tune this more closely.

    As an edit, I found a method EditorSceneManager.SaveScene(). I haven't tried it yet, but it seems to be setup to work through the Unity Editor for assets. If I were to use it in a script complete with in-game UI and specific formatters (scene has 1 player, goal present, enemies present, level is enclosed, if true, save scene to destination with specific file name, etc), would it work at runtime? Or does it only work within the Unity Editor and not when the game is running? Just want to get an idea for when I come back from vacation.
     
    Last edited: Jul 17, 2017
  4. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,519
    Well, at it's most basic a "scene" is a list of objects and their positions, so you can start there. Each scene object can be represented as two pieces of data: the path/ID of its prefab, and the position of the instance in the scene. You can track this by having a script that does the spawning/deletion of your objects and maintains a list as it goes.

    Depending on what you're doing in your scene you may need to store additional data to support your functionality. For example, of objects need to be able to reference each other then they'll all need unique IDs for that to be able to work.

    In short, it's all just data. Saving and loading data isn't difficult in principle. Designing your data format to support all the things you need to do is where things get interesting. My main piece of advice is to not make things any more complex than they need to be.

    Also... keep in mind that C# has a bunch of data serialisation (saving/loading) functionality built in that does not rely on Unity Editor stuff. You can make stuff as normal C# objects, annotate them for serialisation, and then have .NET/Mono do the file format work for you.