Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Universe - Game Managers Made Easy [FREE - RELEASED]

Discussion in 'Assets and Asset Store' started by LightStriker, Dec 2, 2014.

  1. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,598

    Universe on the Asset Store

    Universe Manual

    The Universe is a small free asset that performs a very simple task; it handles all your managers for you.

    You will never have to setup a manager in a scene again! The moment you derive from the Manager class, the tool creates a prefab to host your instance. In the editor, you can press play on any scene, and the Universe loads all your managers for you.

    Because your managers are all at the same place, outside of a scene, you can modify them with ease. You won't need to update any scene with your changes!

    Since your scenes don't requires to be "setup" anymore, it also means they are lighter and faster to load. Every scene just work!
     
    twobob and UnleadedGames like this.
  2. jtok4j

    jtok4j

    Joined:
    Dec 6, 2013
    Posts:
    299
    Hi LIghtStriker,

    I'm cringing while I'm writing this, but can you please give a real-world example of how I as a budding Unity dev, might use this Universe Asset with my projects? I'm trying to wrap my head around this and hope you can help me along.
    Thanks!
     
  3. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,598
    Sure, don't worry, people have been using Unity in a specific way for years, and I'm bringing a different way of doing things. It took people I work with some time to get used to it too.

    Let's take a Sound Manager, right? You need one to play sound, track which one is playing and remove those which are done. It's also useful to keep track of a playlist of music. There's no point adding or removing such manager, you always need one around. Similar to a save game manager, there is no point in creating/destroying one, it should always be there. Another example would be a game-state manager; in which scene are you, in which menu, etc. Or a localization manager, a network manager, a webservice manager, a camera manager, etc. All the game logic that make no sense to ever destroy once your game is running, that you could access at any time, and that they might require hold data or need to have access to an update loop.

    Unity itself is also loading game-wide managers; you can see them in Edit > Project Settings menu. Unity's Input Manager is loaded when the game loads, and it is never destroyed. Sadly, we don't have access to creating our own one the same way Unity does.

    So far, I've seen two ways how projects would usually handle this issue;

    - You are required - in the editor - to load a specific scene so that the game would load and work properly, before being able to load your own scene in order to test it. It usually means you cannot easily create a new scene and simply press play, you have to make the game know which scene you want to test. It means every time you want to test your scene, you have to load another one first.

    - You are required to setup a number of GameObject - maybe prefabs - that hold the game logic in the scene you are trying to test. Not scripts that are related to your scene, but script that would handle game-wide logic. In this case, it means every scenes are required to hold a copy of those logic. They are usually singleton that destroy themselves on awake if there's already a instance in existence. It also means those copies can break if someone add or remove a new manager.

    The Universe adds a third way of doing things;

    - All your game-wide logic derives from Manager. In any scene you want to test, you press play, and that's it.

    What happens behind the scene; there's a script - called Universe - that loads all existing Managers on startup using Resources.Load. It does it by reflection, and if there is not a prefab to hold your new manager, it creates a new one in Resources/Universe. In the editor, there's a tool that the moment you press play, it checks if there's an existing Universe instance, and creates you a temporary one if there isn't.

    It means testing a new scene for your game doesn't require any setup anymore. They just all work.
     
  4. jtok4j

    jtok4j

    Joined:
    Dec 6, 2013
    Posts:
    299
    Greetings,

    Wow, oh WOW. This sounds very interesting and quite helpful for productivity.

    I'm curious to know if there's any performance hits (somewhere in the journey) which results from having this ?always on? sort of setup?

    I'm super-pumped to see this come out and try it, 'cause it sounds super-great! :D

    What has been your experience using it? Where have you noticed the difference most in the areas that it helps to improve?
     
  5. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,598
    There isn't really any performance hit. If you were using the singleton pattern by placing managers in all your scenes, your scenes will load faster by not having those objects in them.

    You don't really have to setup anything... The only step is to derive from Manager like this;

    Code (CSharp):
    1. public class LocalizationManager : Manager<LocalizationManager>
    And... that's it. You're now guarantied that this Manager exist in your game.

    As for my experience, we have a few games shipped using this methodology. So far it works great. It's good to reduce boilerplate code. It means our designers can make new scene on the fly without having anything to setup. It also means that if I need to change some value in one of those manager, all their prefabs are at the same place, so it's easy to edit.

    It also - slowly - pushed people towards uncoupling their inner behaviour from their scenes. For example, our cameras are now in prefabs, and they are instantiated at runtime. So once again, we are not placing those directly in scenes.

    I used to working with video game engine that offer this hierarchy level for managers, so I was quite surprised when I came to Unity and found out there was nothing for it. It's actually the first tool I wrote because I found it completely insane to have to perform any maintenance on scenes to make them work.
     
  6. jtok4j

    jtok4j

    Joined:
    Dec 6, 2013
    Posts:
    299
    Yes, I can see how it would be much easier and time saving to simply have to create the "camera" (for example) one time for the whole game, instead of recreating it for each scene.

    Correct me if I'm wrong, but as I try to wrap my head around your very great, detailed descriptions, I think that it works like this: The main "universe" manager is loaded, and remains loaded during the whole game, so that you don't have to switch scenes? (Meaning, no "Unload scene into nothingness" and "Load a new scene" ? ) But rather the game IS the Universe Manager and "scenes" are somehow loaded unloaded on the fly to work with the already loaded and ready cameras and other resources within "Universe"?
     
  7. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,598
    Well, I wouldn't have worded it that way, but pretty much. It makes scenes what their name implies; a spatial structure of data representing a specific visual context. In other engine, they would call that maps or levels.

    In a game, you usually have macro and micro logic loops.

    A pressure plate, is obviously a micro logic loop, it's self contained and requires spatial data, visual, collider, trigger and so on. It may also interact with other object in its general vicinity; such as opening a door when we step on it. It makes sense to have this one attached to visual objects in scenes. However, the moment I get to the next level, it has no business to stay around in memory.

    The main game state manager which deal with in which level or which menu you are, is an obvious macro loop, it should start when the game start, and stop when the game stop. It's not self contained and interact with many pieces of the game, load scenes, instantiate player or invoke menus. This one makes no sense to have it floating around in a scene since it has no logical connection to one.

    It usually make sense to handle those two differently; their lifespan and their scope is different. Other video game engines usually offer this kind of hierarchy.

    Then there's the "in-between", like a game camera or a player character. They interact with the current loaded scene, but they are not part of one. We usually go in a way like this;

    Code (CSharp):
    1. public class PlayerManager : Manager<PlayerManager>
    2. {
    3.     public Player player;
    4.     public Camera camera;
    5.  
    6.     public Player SpawnPlayer(Transform transform)
    7.     {
    8.         GameObject playerGO = GameObject.Instantiate(player.gameObject, transform.position, transform.rotation) as GameObject;
    9.         GameObject cameraGO = GameObject.Instantiate(camera.gameObject, transform.position, transform.rotation) as GameObject;
    10.  
    11.         cameraGO.GetComponent<CameraBehaviour>().SetTarget(playerGO);
    12.         return playerGO;
    13.     }
    14. }
    and
    Code (CSharp):
    1. public class PlayerSpawner : MonoBehaviour
    2. {
    3.     private void Awake()
    4.     {
    5.         PlayerManager.Instance.SpawnPlayer(transform);
    6.     }
    7. }
    Player and Camera are both prefab I connect in this manager. When I reach a scene where a player is needed, it get created at the right spot. We have independent pieces and we assemble them for the current context.

    This kind of loose coupling means at any time I can modify how the player or the camera behave for the whole game without any modification to any scene. It also means what the player is - its definition - can change. I could have customization logic in that "SpawnPlayer" function, where a player is built piece by piece to how the user likes it. I could also spawn weapons and equipments. We have a game like that, where a similar manager loads a collection of ScriptableObject that represent the definition of different parts, patterns and colors that can be used to create a new character.

    Keeping thing ordered usually makes everything easier.

    Sorry for the walls of text. :p
     
  8. jtok4j

    jtok4j

    Joined:
    Dec 6, 2013
    Posts:
    299
    Once again, thanks for the great explanation. This is starting to be more clear to me, and I'm happily awaiting the news that the AssetStore has it available. :D
     
  9. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,598
    What do you mean? It is available...
     
  10. jtok4j

    jtok4j

    Joined:
    Dec 6, 2013
    Posts:
    299
    *Blinks twice, and clicks the "Universe on the Asset Store!" link... :eek:
     
  11. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,598
    Version 1.0a submitted to the Asset Store with a fix for namespaced class.
     
  12. tosiabunio

    tosiabunio

    Joined:
    Jun 29, 2010
    Posts:
    114
    What about Unity 5 support? Asset Store warns that this version is not compatible with Unity 5.
     
  13. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,785
    Isn't it just warning about containing "scripts"? Asset store warns a lot of things aren't compat but they work okay.
    This extensions literally is a couple of well thought-out files. Let me go drag it in and check
     
  14. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,598
    Haven't check, but it shouldn't contain anything "special" specific to Unity 5. Once I'm back home, I'll check, but it should work fine.
     
  15. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,785
    I'll have a look right now

    EDIT

    I didn't even get a warning it was out of date on 5_0_1f1, just sucked it in and seems fine.
    HTH

    although it does spuriously whine about

    upload_2015-4-2_19-43-20.png

    on the Demos main universe object which probably could be looked into.
     
    Last edited: Apr 2, 2015
  16. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,598
    Do you have any idea how much I hate tracking those?

    That's it! I'm making a damn tool about tracking and nuking those pesky warning.
     
    UnleadedGames and twobob like this.
  17. jtok4j

    jtok4j

    Joined:
    Dec 6, 2013
    Posts:
    299
    Ligh
    LightStriker! I'll be your FIRST customer to buy this tool, if you make it! What a pain it is to track down those error messages! I totally agree! Keep me informed and money's coming your way!
     
    twobob likes this.
  18. RedGreenBlue

    RedGreenBlue

    Joined:
    Oct 14, 2013
    Posts:
    20
    twobob likes this.
  19. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    1,785
    That is what I use. Works fine on 5 as far as I can tell...

    Example:

    upload_2015-4-6_3-33-3.png

    upload_2015-4-6_3-33-49.png

    I should have used it on that project but didn't have it installed.. sigh.. sorry.

    An attractive UI still might have value for the end-user.

    I digress. "Yes, they should work okay"

    Finally: Homage for maintaining this asset through the version change.
    Total respect for that.
     
  20. OnePxl

    OnePxl

    Joined:
    Aug 6, 2012
    Posts:
    307
  21. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,598
  22. yandrako

    yandrako

    Joined:
    Dec 2, 2013
    Posts:
    26
    Im very interested in use this Universe asset, it works correctly with Unity 5 then?
     
  23. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,598
    I haven't tested it on Unity 5, but it should work out of the box. I'm pretty sure it's not using anything that has changed in Unity 5.
     
  24. beef-Supreme

    beef-Supreme

    Joined:
    Aug 26, 2012
    Posts:
    72
    Hi,

    Thanks for creating this. I read a lot about singletons and game managers and your tool makes it easy set up and manage!

    I'm using Unity 5.0.1, But, I'm having trouble when I create a build for android. I have a fairly simple scene setup.

    0 - universe
    1 - main menu
    2 - main game scene
    3 - retry menu

    Universe creates my game manager, which holds the high score and manages the scene loading stuff, among other things. High score is displayed in scene 1 on the menu, and I check if Game manager.Instance is not null before displaying the score.

    Everything works fine in unity editor, but when built for android the GameManager.Instance check returns null...

    Have I missed something?
     
  25. yandrako

    yandrako

    Joined:
    Dec 2, 2013
    Posts:
    26
    I have the same problem building fo iOS. It works on the editor but it doesnt on the device. I probably should manage scenes at some specific way using Universe, but havent resolved yet.
     
  26. beef-Supreme

    beef-Supreme

    Joined:
    Aug 26, 2012
    Posts:
    72
    Hi again,

    I think I've found a work around to the null reference problem - but a word of caution - I'm by no means even an intermediate coder so use with caution :) at least until Lightstriker can check this out ...

    Anyway - I got it working by adding a line to the Universe.cs script. It seems there's a missing call to the Deserialize(); method when the manager prefabs get loaded and you're not in the editor.

    So, find the part the loads the manager prefabs and add "manager.Deserialize();" right after the manager reference gets assigned :

    Code (CSharp):
    1. // None in memory
    2. if (manager == null)
    3.  {
    4.   go = Resources.Load(UniversePath + type.Name) as GameObject;
    5.  
    6.   if (go != null)
    7.    {
    8.     GameObject clone = Instantiate(go) as GameObject;
    9.     clone.name = type.Name;
    10.     clone.transform.parent = Universe.Instance.transform;
    11.     DontDestroyOnLoad(clone);
    12.     manager = clone.GetComponent(type) as ManagerBase;
    13.     manager.Deserialize(); //<<<<< add this line <<<<<<<
    14.    }
    15.  }
    Again - there may be other consequences of doing this which only Lightstriker can tell us, but at least my game is now working again on android :)
     
  27. yandrako

    yandrako

    Joined:
    Dec 2, 2013
    Posts:
    26
    I think have just found the problem. Using the Maintainer (https://www.assetstore.unity3d.com/en/#!/content/32199) I get an error from a missing component at the scene "00 - Universe". Apart from that, if I run that scene from the editor instead other scene, I get four warnings with "The referenced script on this Behaviour is missing!"

    Again, maybe its my fault for not setting correctly but havent solved yet. I try what kinobe say but still the same problem for me.
     
  28. beef-Supreme

    beef-Supreme

    Joined:
    Aug 26, 2012
    Posts:
    72
    yandrako - what you describe sounds like post #15 above. I too was getting those errors using the supplied "00 - Universe" scene. I couldn't track those errors down so just deleted the scene and re-created it. Just make a new scene, delete everything in the hierarchy, then create an empty game object, rename it "Universe" and add the "Universe.cs" script as a component to it. Save the scene as "Universe.unity", and then make sure that this new scene is scene 0 in your build settings.
     
    Cosmos_n_Paradox and yandrako like this.
  29. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,598
    What the... how come I never got any notice from the forums that there was new message here? I'm watching this thread, and never got any warning.

    I feel freaking terrible for leaving such horrible bugs in the store build for so long.

    On top, the Universe we use internally changed drastically in the last year and I just totally forgot to update the package.

    I'm submitting a version 2.0 to the store with the version we are using currently for our own projects.

    [CHANGES]
    • Manager prefabs are created on the code reload, not when pressing play in the editor.
    • The tools relies on the index of the scene (0) instead of checking for the "00" in the scene name. That was dumb.
    • Namespaced all the classes under the Universe namespace. Class collisions are bad.
    • Replaced the ManagerBase class by a IManager interface.
    • Removed the whole concept of "rogue" universe.
    [FIXES]
    • Managers now load properly once deployed in a build. What a terrible bug - my apologize again. (Why nobody told me this?)
    • The tools now relies on the types instead of object names, which is far more reliable. Way less GameObject.Find... like none.
    • Added support for Unity 5.3 SceneManager.
    • Fixed the "Missing Behaviour" warnings.
    By the way, please mail me if you find bugs! I'll fix them right away!
     
    Last edited: May 22, 2016
    sake0706 likes this.
  30. sake0706

    sake0706

    Joined:
    Feb 4, 2018
    Posts:
    2
    Hi guys, does this tool still works in Unity 2018.x? Trying to use it in my project and I've noticed some deprecated/obsolete things in your scripts...
    @LightStriker, would like to see the project still alive and updated... Is this possible? Your website is actually being shut down...? :(
     
  31. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,598
    Yeah.. The website was hacked twice. Simply didn't have time to put it back up a third time. Last time I pretty much lost all the data on it.

    As for the tool, it should work just fine on 2018. We are working on Hellpoint, and it's on 2018.4.3.
     
    sake0706 likes this.
  32. sake0706

    sake0706

    Joined:
    Feb 4, 2018
    Posts:
    2
    Hmm, sorry to hear for the website... I've tested the Universe tool in my project (using 2018.3.12f1) and although some code is deprecated - it really does the job. Nicely done! ;) Do you plan to update it though? Big up on this!
     
unityunity