Tinglee Studios
  • Home
  • Projects

Singleton Prefabs for Unity3D

13/8/2017

0 Comments

 
Picture
We all know about the benefits of using Singletons in our games - you just call YourClass.Instance, and wala! A new GameObject gets created with the class attached immediately at run-time if its not already there. Magic! The common Singleton class for Unity3d can be found at the Unity3d wiki page.

While the Singleton design pattern for scripting has been a revelation, what about the same concept applied prefabs with exposed values or predefined configurations? They will be in the likes of Game Manager, Player Controller, SFX/BGM manager, Message Boxes, and many more.

Picture
For my own projects, I have implemented a modified version of the Singleton class from the Unity wiki page, and it's been super convenient for me since. So I'm gonna share the code with you and I hope it helps you too! Do leave some feedback if you found it helpful, or thought of a better implementation, or if you've faced other challenges using this method.

I'm pasting the code below and also uploaded it to 
Github, so feel free to check it out!
SingletonPrefab.cs

    
0 Comments

    Categories

    All
    Github
    Personal
    Prefabs
    Scripting
    Singleton
    Tools
    Unity3D
    Unity3D Assets

    RSS Feed


    Geeky Sites

    quora.com
    ​
    lynda.com
    leetcode.com
    ​geeksforgeeks.org
    sdtimes.com

About Me

Trained in materials engineering, had some fun in the graphic design industry, and learnt A LOT during my 4 yrs in data operations. I've been from startups to MNCs, all with the hopes of having a stable career. At the end, I chose to follow my heart, and I've never regretted a day since 2013.

  • Based In Singapore
    Leading a small team, developing some cool VR sh*t for the building and interior design industry.

  • Areas Worked On
    Tools  |  UI  |  Animation Controllers  |  VR  |  AR  |  AI Pathfinding  |  Others (a little bit of everything else)


  • Professional Skills
    Unity3D  |  C#  |  GIT  |  Project Management

    Contact Me

Submit

​Copyright 2017 Tinglee Studios