Search Unity

Multiple copies from one model

Discussion in 'Editor & General Support' started by 12domb18, Sep 6, 2019.

  1. 12domb18

    12domb18

    Joined:
    Nov 13, 2018
    Posts:
    6
    I'm new to Unity/Game Dev but I'm an experienced programmer in general (ETL work mostly)

    I have a singleton that holds a list of 3 models. I have two game objects with the same C# class that on the Awake() method:
    • Goes through the list and Instantiates each one
    • Stores the new model in a local copy of the list
    The code looks like this:
    Code (CSharp):
    1. foreach (Character Model in GameManager.Instance.GetCharacterList())
    2.         {
    3.             Character temp = Model;
    4.             temp = Instantiate(temp );
    5.             temp .SetActive(false);
    6.             characters.Add(temp);
    7.         }
    (I have 2 instances because the character the user will control also has a helper that pulls from the same model original list. If this was Nintendo, I'd say that I have a Mario as my main character, and I want Mario to be able to be my helper character. This all works fine if I have Mario as my main and Luigi as my helper, but I want to leave the option open to have Mario as both)



    To continue on my Nintendo example, I select Mario as main character, and then when I select Mario as the helper, I can see the former snap to the position of the latter. The hierarchy tells me they're looking at the same model, but I want each class to look at the specific Model they instantiated, not the last instance of the model that was instantiated.


    One important thing to note is that both classes are creating the GameObjects in the Hierarchy, but one set is being pulled from by both classes.

    I'm sorry if this question has been asked before, and I have NO problem RTFM, but after much debugging, googling and searching I'm completely stumped.

    Also, I'm sorry for screwing up the vocab. I'm new to Unity so when to use Class, Model, Prefab, and GameObject is kinda blurry to me.

    Thank you for your time!