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

Handling a mesh change?

Discussion in 'General Discussion' started by tclancey, Jun 13, 2020.

  1. tclancey

    tclancey

    Joined:
    May 19, 2017
    Posts:
    143
    Hi there.

    I'm trying to make an object fall into distinct parts. I have model A (the complete mesh) and the children modelled, the children are just parts of the original A.

    How - in the script of A - do I hide A and invoke the children?

    I think I'm ok with suddenly creating or just showing the children, but how would I hide A? I can't turn it off as I still need the code running. I can't find any options for just 'hiding' an object.

    Also, I need everything to have a collider and rigid, am I safe to carry the broken parts around as children (which will effectively be inside A), or should I really create them when they're needed?

    Thanks.
     
  2. unit_dev123

    unit_dev123

    Joined:
    Feb 10, 2020
    Posts:
    989
    maybe this:

     
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,321
    Have a "root" object which would be empty GameObject with coding component attached.
    To the "root" object, add "normal state" and "destroyed state" children. There, configure whatever you want. Normal state is the object in pristine state and "destoryed state" is where it is broken into pieces.

    By default "normal state" will be active, and "destroyed state" will be hidden (active == false).
    When it "breaks", hide "normal state" and unhide "destroyed state". Both objects can have their custom set of colliders, completely different meshes and so on.

    This way "root" remains active with its scripts running, but visual state changes when you need it, by hiding and unhiding relevant children.

    Of course that's the simplest way to do it. Instead of hiding and unhiding you could actually destroy and instantiate relevant visuals, but the point is not to put code that you need to keep running onto mesh you're destroying in the first place.
     
    Ryiah likes this.