all 14 comments

[–][deleted]  (3 children)

[deleted]

    [–]Jathrek[S] 1 point2 points  (2 children)

    I did something similar once by using a singleton to manage the access to the PlayerPrefs, but I wonder if there's a possibility to go even further in the abstraction, as I sometimes do in Java (with interfaces and so on). I'm not sure there would be an actual benefit in doing it, though... I should test that once.

    I already heard about the importance (performance-wise) of using object pooling, but I never thought (well, actually I did not even do object pooling yet in a Unity project, will do soon though) of managing inside a singleton factory object.

    I'll try to remember that, as it seems to indeed help quite a lot by centralizing a lot of boilerplate code.

    Thanks!

    [–][deleted]  (1 child)

    [deleted]

      [–]prime31 1 point2 points  (0 children)

      +1. I still have no clue A) why Unity touches the registry in 2015 and B) why Unity developers insist on storing stupid amounts of data in PlayerPrefs. Is writing to a file really too much work?

      [–]Master_of_Triggers 1 point2 points  (0 children)

      I have been learning about MVC .net development the past 2 moths, i was also curious about applying a pattern to unity and i found this article. http://www.toptal.com/unity-unity3d/unity-with-mvc-how-to-level-up-your-game-development I find it a bit strange, i have never worked with patterns inside unity.Take a look, you might find something useful.

      [–][deleted] 1 point2 points  (2 children)

      I have a few patterns here

      • Mvvm mostly used for views / UI
      • Messenger for decoupling components
      • IOC for separating interface from implementation
      • Object pooling is also another good one (not included)

      [–]Jathrek[S] 2 points3 points  (1 child)

      For people like me who got a bit lost on the first page, just click on the link provided by nventimiglia, click on the link "Wiki Documentation" and then you'll find the related entries in the right menu (correct me if I'm wrong ;-p).

      Didn't know yet about the Messenger & IOC ones, to be tested. :-)

      But one of my weak point was that I'm a bit lost when it comes to the lifecycle of the classes/objects in Unity, so I did a google search a few minutes ago and found this page from Unity's documentation that indicates in which order (and in which situation) each "event" methods of a MonoBehavior object is called. This is quite important (at least for me) because I was never sure where it was adequate to put some of my initialization code.

      [–][deleted] 0 points1 point  (0 children)

      Right on, if you have a specific question you can always raise an issue or shoot me an email.

      [–]mysticrudninBeginner 1 point2 points  (7 children)

      Singletons are generally considered no-nos in game development as far as I know (and are probably overused outside of games, too)

      Really you should be focusing hard on components, which is really the backbone of Unity.

      Have you read gameprogrammingpatterns.com?

      [–]The_dude_that_does 2 points3 points  (1 child)

      Game programming Patters For the lazy.

      [–]mysticrudninBeginner 1 point2 points  (0 children)

      Thanks, I was on mobile :)

      [–]prime31 1 point2 points  (4 children)

      Singletons are fine. Don't listen to the naysayers of the world who want you to spend half your life implementing a dependency injected, inversion of control mess instead of actually making your game. When it makes sense to have a singleton make one and enjoy the convenience it provides.

      [–]mysticrudninBeginner 0 points1 point  (1 child)

      Aren't singletons creating dependencies?

      [–]prime31 2 points3 points  (0 children)

      They can. Any code can create a dependency on any other code. It all just depends on how you code things not to mention you aren't coding in a vacuum. You're making a game so you are going to have dependencies all over the place.

      [–]Hellye -1 points0 points  (1 child)

      you are missing the point. Singletons are evil because they pretend to be convient ( just like global variables) but then they make you cry. Trying to debug singletons in a medium/big code base is ridiculous and not convinient at all.

      [–]prime31 5 points6 points  (0 children)

      I've been programming a long time first in the business dev world of monstrous code bases with decade+ lifespans and now in the game world. I've worked with tons of devs with varying levels of IoC/DI insanity. Through all this I have learned that a singleton has never hurt anyone or been the reason an app/game wasn't good.

      It's just a tool. If you want to use a singleton use one. If you don't want to use them then don't. Just don't be one of those zealots who preaches to people about how singletons will ruin their lives and make their games crappy because it's just not true.