Search Unity

Confused about prefab instancing

Discussion in 'External Tools' started by Innovine, Dec 28, 2018.

  1. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    Hi,
    I would like to lay out most of my level directly in blender, and then import into unity and attach scripts to the objects. However, i have many small, repeating details at different locations. It seems like Unity expects me to create a prefab asset for each of these in the editor, so as to batch things together for performance. I cant do this due to many reasons (mainly that the editor camera movement is so bad for tiny details, and top/left/side views and hiding geometry allow me to position more accurately and easily in blender). Should i just duplicate hundreds of objects in blender and position them with no thought to re-use and prefabbing, or is there a better way? Could i place empty points in blender as location markers, and parent assets to those in unity? What other ways can i approach this?
     
  2. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    726
    Unity's prefabs are for sure the way to go if you want modular assets that are generally the same thing but repeated. You only have to create the prefab once though, and then you can make as many duplicates as you want in the scene view. That's kind of the point of prefabs. It also lets you change them after you've already placed them, and then that change automatically applies to all those duplicates.

    So, assuming you use this approach, you wouldn't make levels in Blender at all, rather you would make modular level pieces, like walls, corners, floors, etc... think tiles but in 3d. Then in Unity, you would turn each of those modular pieces into a prefab, adding scripts and other child objects if those are separate but need to be included on all the duplicates. Then, in the scene editor, you would throw those prefabs around to make your level. The newest version of Unity also lets you nest prefabs properly, and you can also override properties, allowing a single prefab to power a few slightly different versions of itself.

    Then, you can either add colliders to each prefab, or you could make large colliders that go through all prefabs, like a massive plane collider for the whole floor(instead of a collider for each floor piece).

    So yeah, I would say for sure not to duplicate objects anywhere, Blender or Unity, and get into the prefab system. If your levels can't be built totally using modular pieces, then of course, build them in Blender, but then add any modular or duplicatable(is that even a word?) pieces in Unity. So maybe your levels walls, etc... can't be done with modular pieces, but furniture, wall torches, pillars maybe, and other similar things could be.
     
  3. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    241
    This is one of the major problems I am having... I need to position things with millimeter accuracy, and the Unity editor camera movement is absolutely dreadful. I tried the beta where the camera movement can be slowed down but the editor is really sluggish for me. The only way IU've found to deal with this is scale up objects by 50x, then position things, then scale them down again. It is a total PITA.

    It may help to say that I'm building the inside of a cockpit, where the play area is very small and highly detailed, but there are large expanses outside where the ship can fly around, so I'm using the default unity scale of 1u = 1 meter.

    A second issue is that I am struggling with how to bake ambient occlusion maps, if the parts are assembled in Unity. I do a lot of texturing in Substance Painter so exporting the whole model and baking various maps makes a lot of sense.

    Another issue is for example, a control panel with 30 interactive buttons on it. What's the best way to approach this? I try things like modeling everything in Blender, and using two materials, one for the buttons illuminated, one for them dark, and I export everything to unity. I then attach a push button script, which moves the button, swaps the material, and have an event generator attached to each button which fires when they are pushed. The button object is identical in every case aside from the UVs. Is this still the best way to approach this or are there better alternatives?
     
  4. kburkhart84

    kburkhart84

    Joined:
    Apr 28, 2012
    Posts:
    726
    I'm not sure what issues you are having with the editor's camera, it works fine for me. About the positioning your objects, look up "snapping." It lets you match up your objects to each other directly, edge to edge, vertex to vertex. This will let you easily make things work on a tile grid kind of thing.

    About #2, if your modular pieces only need the AO for themselves individually...as in they aren't going to add AO to each other, then you can still model and texture them separately. If they should be affecting each other in the AO bake, then sure, it makes sense to build out the level in Blender and work with it as a whole. That said, normal light mapping will still work fine either way you go. There are advantages to each workflow, where one is more friendly to putting things together quickly, while the other allow much more detail.

    There is nothing wrong with re-using the same button model and materials for all 30 buttons. If you want to them to look the same, that is about the only way to do it without wasting time. I'm not totally understanding what you are doing though. Are your buttons in 3d or are they working in screenspace?