Search Unity

How to separate one GameObject into multiple pieces

Discussion in 'World Building' started by bassboosted_Tragedy, Jan 2, 2019.

  1. bassboosted_Tragedy

    bassboosted_Tragedy

    Joined:
    Jan 1, 2019
    Posts:
    19
    Sorry for another rookie question, but is it possible to break up a game object into other pieces? If so, how would I go about doing that? I assume this is much easier than I think it is, but I'm just playing it safe as to keep from breaking anything Thanks so much for any help.
     
  2. alussam

    alussam

    Joined:
    May 13, 2018
    Posts:
    15
    You shold use blender for this purpose or other similar application. In unity it is impossible
     
  3. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Breaking gameobjects into pieces can be done by creating other gameobjects and putting some of the scripts from the first one onto these (if they don't have relative references to certain hierarchy elements). But you're most likely wanting to know how to split geometry/meshes; and that indeed should be done in a 3D-modelling package. It can be done inside unity, but is not recommended and can potentially be very complex, depending on the model.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Or, depending on what you're trying to do, you may find something in the asset store that does it. There is an asset called (IIRC) "Exploder" which does a pretty good job of exploding most meshes. Or, for Beatron 2000, I wrote a little script that breaks any mesh into its constituent triangles, and sends those flying (for a Tron-like explosion).
     
  5. gabrielw_unity

    gabrielw_unity

    Unity Technologies

    Joined:
    Feb 19, 2018
    Posts:
    963
    Hi, you can use ProBuilder for this! :)

    1. Drop the mesh into your scene
    2. Open ProBuilder, select the mesh object in your scene, and click "ProBuilderize" (in the future, this will be seamless, sorry!)
    3. Use ProBuilder to select the faces you want to "break off" to a new mesh
    4. Click "Detach Faces" (note: you can click the little "+" next to the button to choose whether the faces become a new GameObject, or SubElement in the same mesh!)

    Hope that helps! Here's more info from the docs:
    ProBuilder: Detach Faces
     
  6. gabrielw_unity

    gabrielw_unity

    Unity Technologies

    Joined:
    Feb 19, 2018
    Posts:
    963
    Separete note: as others have mentioned, it is often best to do this in a separate editor (Blender, Maya, etc). Using ProBuilder is (for now) a somewhat clunky method, and will be tough if you have very complex mesh. However, if you just need a quick separation of chunks, and also want the benefit of further editing in-editor, ProBuilder will do the job nicely :)
     
  7. Honorsoft

    Honorsoft

    Joined:
    Oct 31, 2016
    Posts:
    81
    Just commenting because the advice here is lacking and pushes using 3rd-party 3D software to make "pre-broken" versions of models. It is possible to break apart things in Unity during runtime, without having to break apart objects in a 3D editor or ProBuilder and then switching objects during runtime. It is quite easy breaking a mesh apart into shards, chunks or any shape you want really. Two things to consider are models broken into vertice triangles will slow down Unity if there's too many of them. Also, meshes are hollow, so when you break them, you have to also weld the pieces so they look like solid chunks. It isn't hard to have the texture applied to the pieces so that the pieces keep their texture. I have written a script that creates a Voronoi fracture to any mesh object in Unity, and it also starts the Voronoi pattern generation from the initial collision point to give a realistic shatter to the mesh object. I will post a more basic version of the script here soon when I get some free time, but in the mean-time, read up on Unity's mesh filter component.

    Just as proof that it IS possible to break up a game object into other pieces and it will look realistic and work fast, here is a screen shot of a test-game running in Unity that uses different versions of object shattering in real-time, breaking the actual mesh into chunks:

    (The objects are the white ones which weren't textured yet, the grey square is just to hide the test-character.)
    The headless Statue of Liberty can be seen in here, broken in realtime and automatically welding the base model and the chunks to fill in the holes in the meshes. This was a test using Unity 5. I have more projects and some using Unity 2018 and 2019 and I will post more here soon. Not the best screenshot, but it is proof that even complex models can be easily broken in Unity, without Blender or premaking broken versions of the original object and swapping them, it also worked near-instantly fast, even on an old Windows 7 32-bit system.

    Here's a couple of demonstrations from others using Unity, shattering objects in realtime:

    http://emretanirgan.com/portfolio/dynamic-voronoi-fracturing/

    and....

    https://keithmaggio.wordpress.com/2019/05/28/links-voronoi-symphony-of-destruction-and-more/




    All the pics posted are from Unity projects, and works on versions 5 through 2019 (maybe earlier too).
     
    Last edited: Sep 11, 2020
    firejerm, danisawesome0 and Kjelle69 like this.
  8. tclancey

    tclancey

    Joined:
    May 19, 2017
    Posts:
    143
    Looking forward to some code for this, way beyond my head to work out,but I'd love to use something similar.
     
  9. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    How exactly do you do this bit?
    3. Use ProBuilder to select the faces you want to "break off" to a new mesh

    After probuilderizing I dont see any menu or anything come up.
     
  10. topitsky

    topitsky

    Joined:
    Jan 12, 2016
    Posts:
    100
    There should be a feature builtin to allow the chunking of meshes, say you have a huge mesh and want to divide it into 4 separate parts for more efficient rendering.
     
  11. gabrielw_unity

    gabrielw_unity

    Unity Technologies

    Joined:
    Feb 19, 2018
    Posts:
    963
    Hi! Oops, I wasn't very clear on that - to "break off chunks" :p , use the "Detach" functionality - here's an old but helpful vid:

     
    radiantboy likes this.
  12. topitsky

    topitsky

    Joined:
    Jan 12, 2016
    Posts:
    100
    Needs to be done runtime for generated levels
     
  13. Honorsoft

    Honorsoft

    Joined:
    Oct 31, 2016
    Posts:
    81
    Sorry I haven't had a lot of time and I have been flooded with projects to work on, but those links I posted should take you to those free example projects. Most, if not all have tutorials to follow.
     
    Last edited: Jan 19, 2021
  14. Kromm271

    Kromm271

    Joined:
    Jun 29, 2019
    Posts:
    1
    Just ran into this issue myself. It would be really convenient if the Probuilder API had the ability to detach faces as gameobjects/submeshes. You have to option to do so in the editor, but I can't find anything related in the API documentation beyond proMesh.DetachFaces(). There doesn't seem to be a straight forward way to convert the detached faces to gameobjects.
     
    comomomo likes this.
  15. Honorsoft

    Honorsoft

    Joined:
    Oct 31, 2016
    Posts:
    81
    I have spent a lot of time experimenting with mesh manipulation in Unity, and I had success with using scripts to do all sorts of things with faces and submeshes. It can get a little harder dealing with sub-meshes, but maybe try searching online for Unity code that deals with mesh/face manipulation.
     
    camillo777 likes this.
  16. camillo777

    camillo777

    Joined:
    Apr 20, 2015
    Posts:
    10
  17. TheMstWntd

    TheMstWntd

    Joined:
    Mar 7, 2020
    Posts:
    2
    You sir saved my LIFE! I am new to Unity and I merged all of the walls and floors of a room WITHOUT giving them a material first. Just now I realized my mistake but you saved me!
     
    bugfinders likes this.