Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clon on addChild or just set as parent ? #2

Closed
alejodaraio opened this issue Mar 3, 2017 · 0 comments
Closed

Clon on addChild or just set as parent ? #2

alejodaraio opened this issue Mar 3, 2017 · 0 comments

Comments

@alejodaraio
Copy link
Contributor

alejodaraio commented Mar 3, 2017

I dont know why create a new GameObject on AddChild when just you can set the current clone object as parent

Original:

private GameObject AddChild (GameObject source, Transform parent)
{
    var target = new GameObject (source.name);
    target.transform.parent = parent;
    target.transform.localPosition = source.transform.localPosition;
    target.transform.localRotation = source.transform.localRotation;
    target.transform.localScale = source.transform.localScale;
    return target;
}

Change:

private GameObject AddChild (GameObject source, Transform parent)
{
     source.transform.parent = parent;

      foreach (Transform child in source.transform)
      {
          GameObject.Destroy(child.gameObject);
      }

     return source;
}

So when implement Stitch you don´t need destroy cloned gameobject:

private void Wear(GameObject clothing) {

 if (clothing == null)
            return;

  clothing = (GameObject)GameObject.Instantiate(clothing);
  wornClothing = stitcher.Stitch(clothing, avatar);
}

And with this logic copy also the components from original object.
I suggest it because in my game my items have required components so with the original logic i lost the components.

Cheers.

@alejodaraio alejodaraio changed the title Clon on add Clon on addChild or just set as parent ? Mar 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant