Why does this code change the tag and name on the prefab itself?

Hi,
I have problem with this piece of code that change the tag and name on the prefab and not the instantiated object, or is it somewhere else in the code. Could someone please comment on this?

                    str_flipCardContainer = replayParent_GO.tag;
                    str_flipCardContainer = str_flipCardContainer.Substring(1);                                // Remove the "_"
                    str_flipCardContainer = str_flipCardContainer.Remove(str_flipCardContainer.Length - 1); // Remove the "B"
                    flipCardContainer_GO = Resources.Load (str_flipCardContainer) as GameObject;
                    str_flipCardContainer = "_" + str_flipCardContainer;
                    flipCardContainer_GO.name = str_flipCardContainer;
                    flipCardContainer_GO.tag = str_flipCardContainer;
                    flipCardContainer_GO.transform.position = replayParent_GO.transform.position;
                    flipCardContainer_GO.transform.localEulerAngles = replayParent_GO.transform.localEulerAngles;
                    flipCardContainer_GO.GetComponent<Renderer> ().sortingOrder = sortOrderForFlip;
                    sortOrderForFlip++;
                    Destroy (replayParent_GO);
                    bigDummyGO = Instantiate (flipCardContainer_GO) as GameObject;
                    bigDummyGO.name = str_flipCardContainer;

I believe you need to Instantiate the object before you edit the gameobject details.

So just move bigDummyGO to the top, and change bigDummyGO.name, and bigDummyGo.tag

@

Thanks, i just realized that my self :slight_smile: …will test that[/QUOTE]

flipCardContainer_GO.name = str_flipCardContainer;
flipCardContainer_GO.tag = str_flipCardContainer

These are the two that are changing the name and tag of the prefab.

Let me know if it works! But I believe thats the fix :wink:

It worked :slight_smile:

1 Like