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. Dismiss Notice

Writing Singletons, Help

Discussion in 'Scripting' started by graviton, Oct 26, 2014.

  1. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,377
    Watch, I'm going to google your question.

    I'll use 2 keywords to google.

    "unity singleton"

    Because I want links about singletons in the context of unity.

    https://www.google.com/?gws_rd=ssl#q=unity singleton

    Note the first 3 results:

    http://wiki.unity3d.com/index.php/Singleton

    A wiki discussion with exmaples of how to do it.


    http://answers.unity3d.com/questions/20949/singleton-implementation.html

    A unity answers page clarifying to a user who didn't understand what a Singleton was with examples and resource links.



    http://unitypatterns.com/singletons/

    A blog article about the Singleton pattern and multiple versions of that pattern with explanations of the differences.



    There is a wealth of information there that could be had in seconds. Mere seconds. I had to type fewer words than is necessary to post the question here.

    With said information, you would have known how to implement a correct Singleton. As opposed to the broken singletons you posted in your question. Which derailed the discussion since people pointed out that what you posted wasn't even a Singleton... making it difficult to actually answer your question in the first place.

    You could have even gone on to ask any even more informed question. That being "why is it these versions of singleton look so different from what I originally thought a Singleton to look like?"
     
    GarthSmith likes this.
  2. graviton

    graviton

    Joined:
    Jan 11, 2013
    Posts:
    75
    @lordofduct
    Well regardless of what the definition of a forum is and how you feel they should be use, however right you may be

    The fact still remains that many if not most of us use forums as answer machines

    Unlike "Unity Answer" where it's difficult to get someone to further elaborate on their reply and having to wait for that extra comment to get approved by a moderator

    In forums many say, "hey look at my code and tell me what I'm doing wrong" and when the reply isn't clear they a can simply ask for further explanation and get a reply almost immediately (depending on timing). Since it’s in a discussion format people tent to check in for updates which is useful when you need them further explain their replies

    I post most of my questions in both Answer and forums, and most of the time I get faster replies from the forums than I do in Answer, sometimes before my question even becomes public in Answer

    I'm not disagreeing with you as to what constitutes the nature of a forum, I'm just stating that forums are effective for getting answers, since many of us use them as answer machines, however wrong it may be to do so
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,377
    Yes, they are effective.

    That's why I hang out here.

    Just don't be surprised when other people don't respond as you expect. Because they may be using for a different purpose.

    Note this came up because of your post where you said:

    You speak of an expectation of a "proper response". This implies that you're operating under the assumption we all agree that a forum serves the purpose as you defined it.

    Then you say that you don't disagree with me, that you do know that forums are used for more than that, and that each individual views it differently.

    cake and eat it too

    Suddoha expects you as a member of the community to put more effort into your posts, where as you don't expect to. You expect "put question in, get answer out". Suddoha expects, "propose idea, discuss idea, if OP doesn't understand fundamentals of idea then OP needs to gather more facts before continuing discussion".

    This is a public forum, you have to deal with the public in that respect. Suddoha attempted to claim they aren't trying to be rude with a clarification:

    This was Suddoha "asking for clarification" as you requested. Funny thing is, you tell him to ask for clarification by quoting the very paragraph he asks you for clarification!
     
  4. graviton

    graviton

    Joined:
    Jan 11, 2013
    Posts:
    75
    @lordofduct

    First of all my problem with Suddoha is with the fact that he dogs my threads giving me "hints"

    When I said to ask for clarification I was referring to Suddoha's first post and meant in general, it's common sense (if you don't understand the question, ask for clarification). The second post as you state "paragraph he asks you for clarification!" was already after I'd gotten my answers. Others also told me it wasn't a real Singleton but they also explained why and even showed examples, they didn't first wait for me to ask "what do you mean?"

    My point simply was that if he's just going to troll my threads with his “hints”, then I'd much rather he not bother replying to my posts at all

    and I don't really understand why you've decided to champion Suddoha anyway or why you can't seem to understand where I'm coming from, the other guys seem to get it

    You and Suddoha must be real close that you can speak as to his inner workings like this. "Suddoha expects, propose idea, discuss idea"

    at any rate, I'm getting tired of talking to a brick wall and I'm starting to feel like I'm getting pulled into a Troll Cave

    So let’s just agree to disagree

    Btw, your previous post surely speaks volumes as to the effectiveness of forums. Because I used the forum I didn't have to google search and sort through a lot of irrelevant stuff in an effort to separate the useful from the not so useful stuff, instead you took it upon yourself to google, skim though and point out the useful stuff for all of us

    Anyway thanks for the chat, it's been an experience
    http://www.wikihow.com/Stop-Being-a-Condescending-Person
     
    Last edited: Oct 29, 2014
  5. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,377
    I'm not "championing" Suddoha. I'm merely trying to show you a different light under which to interpret what he says.

    I also understand where you're coming from. That's why I've suggested the various reasons for coming to a forum, as well as agreed that I enjoy forums for the answers they give.

    I just think you're being very short sighted in getting annoyed that people aren't giving you answers in the format you expect.

    Maybe his "hints" are him trying to point you in the right direction.

    Again... the whole "teach a man to fish" mentality.


    1) Yeah, so much skimming and seperating out the useful from the non-useful. I merely selected THE FIRST 3 RESULTS.

    2) And do you not see why some people may think it's rude that you expect them to do the work for you???



    I love the irony of your implication at the end that I should stop being a condescending person. How about a little introspection on your own statements before suggesting such a thing.
     
    Suddoha likes this.
  6. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    The first input i gave (before asking any further) was that the implementation you posted doesn't quite fullfill the idea of the pattern you connected it with. Before i start to help it may help what's the real aim of the topic. It could have been that you really wanted a singleton in this case while not knowing it isn't even one.

    Example: You're looking for a street named 'XXXX' which is pretty close, but you're confused and ask for 'XXX' which is 2 miles further away, wouldn't you appreciate if that person asks first whether you really meant 'XXX' (which is far away) or 'XXXX' because it is nearby?
    In this case it makes much more sense to know first where you really wanna go and then start to explain the route.
    With your current argumentation you'd rather take the wrong route, because you don't want to be told you might be looking for the wrong one. Awesome.

    My comment doesn't do anything else. I could have written my personal answer, not bothering (in this case would be 'not bothering much') that it's something totally different.

    And It's still topic related, even though it does not answer your question. If that's not what you were looking for and don't want to hear/read/think about that, simply ignore it.

    But what's wrong with you saying it's a 'stupid hint' and kind of worthless when someone tells you about possible misunderstandings? Who's acting rude here? I guess i'm not.

    That's pretty arrogant.
    See above, plus it's a forum, what do you expect? It's not a direct customer support by the company, if someone is kind and wants to help, he's allowed to, so am I.
    Nowehere have i said everything's directed to me, but you act yourself as if people have to do what you want, in this case post only the stuff you want to hear something about. That's not what forums exist for, sorry.

    Adding 'no offense' means, if you interpret my post as an offensive one, you should at least know that it wasn't meant to be. Offenses are subjective, since I don't know you I couldn't have known that you interpret it that way. I'm sorry then.
    I actually added that line because i had the feeling something like that would come up.
     
    Last edited: Oct 29, 2014
  7. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    My preferred method of singleton implementation these days (for monobehaviour based)

    Code (csharp):
    1.  
    2. public class MonoSingleExample : MonoBehaviour
    3. {
    4.    static MonoSingleExample _instance;
    5.    static MonoSingleExample GetInsance()
    6.    {
    7.      if(_instance == null)
    8.      {
    9.         _instance = new GameObject("_MonoSingleExample").AddComponent<MonoSingleExample>();
    10.        DontDestroyOnLoad(_instance.gameObject); //only required if your singleton will be used in multiple scenes
    11.      }
    12.  
    13.      return _instance;
    14.    }
    15.  
    16.    public static string GetName()
    17.    {
    18.        return GetInstance().name;
    19.    }
    20. }
    21.  
     
    graviton likes this.