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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Duplicate Objects in Unity or Modeling Program?

Discussion in 'Formats & External Tools' started by TizzyTool, May 29, 2015.

  1. TizzyTool

    TizzyTool

    Joined:
    Dec 20, 2012
    Posts:
    6
    I'm building out a model of an apartment building interior, which has a lot of repeated geometry/materials, for example, the moulding around the floors/ceiling.

    I'm guessing the most efficient processing of the scene would be to minimize duplicated geometry by having one model defined for, let's say the moulding around the ceiling, and then "reference" that one model in multiple locations/rotations/scales throughout each wall in each room.

    My question is: What's the best practice for duplicating models? Do you have to do it in the game engine, e.g. Unity, or can you do it in a modeling program and still get the performance benefits when importing into the game engine? It would be nice to model the entire thing in one program.

    Thanks in advance.
     
  2. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    910
    I think it depends on the situation, specifically, consider the following things.

    1. On which side is it easier to do the duplication, Unity or your software?

    2. Performance...Unity will be able to draw the duplicated things together, assuming the use the same materials, which they should if things are duplicated right? But, if things are all the same model, it is likely to be slightly better. This is because it would all be one draw call anyway if it is all the same model/material. And you wouldn't have the issues of multiple objects, child gameObjects, etc...

    3. How much are these duplicated pieces likely to be changed, which would then need to be applied to the rest of the pieces.

    In my opinion, in many cases, you will be better off doing these things in your modelling software, and keeping things on as few objects and materials as possible for performance. One thing that can be done is keeping things in your modelling program in a modular form. So, you can set them up to easily be separate objects, ready for you to change the original and instance the changes out. And then you can merge those objects for actual Unity usage. But keep the original setup so that you can make changes if you need.
     
    theANMATOR2b likes this.
  3. TizzyTool

    TizzyTool

    Joined:
    Dec 20, 2012
    Posts:
    6
    Thanks for your response. Sounds like "instancing" in the modeling program will allow for easily updating all copies of a source model, but I can also always make a copy and save that out as a one-off.

    Can you clarify:
    And possibly related: if I have a model "instanced" in the modeling program, as you suggested, when I export it, e.g. FBX, will Unity understand that it's one model and just "instanced" all over the place? Will it only have one set of points saved per mesh, and then just different translation/orientation data for each "instance"?
     
  4. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    910
    You would save the model as a single model, making "real" all of the instances, so Unity wouldn't know about the fact that these are instances of something. So it would indeed have the geometry copied all over the place, stored as many times as it repeats. But, if it is all actually part of one object, than this is fine and probably better.

    Now, if you are wanting to build a world out of modular pieces, like 2d tile-based worlds, but in 3d, that is a perfect way to go. You just have to make sure the pieces can fit together generally, and there are tutorials that help with that. Then, if you import just the pieces into Unity, then you can put it all together in Unity. The model would be only stored once for each piece, but there would be many transforms, etc... for all the different copies, as that is needed to actually draw them. This is also acceptable, and makes good sense if your game world can be built like that. This is even better if your pieces can be built off a single texture and material, as then Unity can batch the drawing into 1 or few draw calls as if it was all one big model.
     
    theANMATOR2b likes this.
  5. Pix10

    Pix10

    Joined:
    Jul 21, 2012
    Posts:
    850
    If you want instancing you can do this by exporting nulls in place of your instances in your modelling package, and replace them in your scene with copies of the instances (with the nulls retaining the transformation properties of the instances).

    This will require scripting at both ends - substituting the instances in the 3D app (unless the application has something akin to 3DS Max Bone Tools which lets you flag an object as a bone via Bone On, which will be exported as a null, or you're using Houdini, which is particularly good at this sort of thing), and substituting the nulls in Unity.

    But unless your geometry is particularly high density, there's probably not much of a pay-off. Better for performance may be simply taking care to split your geo into culling groups.
     
    theANMATOR2b likes this.
  6. bennyboy

    bennyboy

    Joined:
    May 5, 2015
    Posts:
    13
    Do it in Unity. You can build prefabs out of several pieces, can build new prefabs out of a collection of smaller prefabs, and can edit each real-world instance to be different than the prefabs. Being able to do all this is one of the main points of using Unity, imo. If your pieces are properly designed to regular sizes so they fit together nicely, then with a couple dozen pieces, you can easily slap together all kinds of neat stuff.