Search Unity

Generate UI images/sprites from Mesh/FBX/etc?

Discussion in 'Editor & General Support' started by viveleroi, Jun 1, 2018.

  1. viveleroi

    viveleroi

    Joined:
    Jan 2, 2017
    Posts:
    91
    I have a bunch of 3D items that will be represented in an inventory (UI Images, really). Since I don't believe you can actually use those meshes in the UI, I'm trying to determine the best way to create those sprites.

    I was hoping to find a way to automate it but I think it will have to be on a case-by-case basis, some items are smaller, some may require different camera positioning, etc.

    Should I just manually render each item in blender with fairly close-in camera and a transparent background?
     
  2. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    There a few ways to do it. 1) you can place 3D items in the ui, it’s a little tricky to manage anchors an scale, especially with a fluid layout, but you can use locators in you canvas to help with that. 2), you can use a render texture and off view cameras. This is a little more complex, in terms of management, but allows for normal flow of ui structure. 3) just build your ui in 3D and use world space canvases for 2d ui elements.
     
  3. viveleroi

    viveleroi

    Joined:
    Jan 2, 2017
    Posts:
    91
    Thanks, I had come across the render texture approach from some early research, but I think all of these all more effort/cost than they're worth. I don't think any of these offer any benefits over one-time render and export of each model in blender. Sounds like they come with some other problems/caveats.
     
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    That is true. If the goal is primarily having an image of the object, then rendering out the images is probably the best approach. The other methods are very doable, I have done them in several recent games, but in those cases the goal was specifically to have 3D/animated items in the ui. If that isn’t the case, 2d would be a better approach.
     
  5. viveleroi

    viveleroi

    Joined:
    Jan 2, 2017
    Posts:
    91
    I'm tempted to try the world-space UI, it would be nice to be able to use the same objects as I do in-world and the options that provides. Plus, having actual 3d items instead of pictures would be neat.

    Edit: After basic testing, I'm not sure that's going to work. I can get the UI to look right but the meshes wind up being affected by my fog and other lighting settings. I looked up a few ways to prevent items from being affected by fog. Looks like I can either copy the shader (in this case, Standard) or I can setup a specific camera and turn off fog OnPreRender and turn it back on OnPostRender...

    That works. I had to tweak my world light source culling mask to the ignore this later, and add a special light only for this layer (so the inventory items aren't lit by in-world sources), but I think this works for my needs.

    Thanks!
     
    Last edited: Jun 1, 2018