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

Question Add rotating 3d model to a visual element?

Discussion in 'UI Toolkit' started by ElevenArt, Jun 2, 2023.

  1. ElevenArt

    ElevenArt

    Joined:
    Dec 12, 2012
    Posts:
    16
    Is it possible to add a rotating 3d model to a visual element? I would like to use it in the inventory. Officially, there is no such functionality yet, but could it be coded somehow?
     
  2. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    296
    You have to use a render texture.
     
  3. Hellfim

    Hellfim

    Joined:
    Sep 11, 2014
    Posts:
    91
    As mentioned above you should use RenderTexture. To be more sprcific you need to have your model in the scene and a camera targeted to the model. Camera's render target should be set as RenderTexture.
     
  4. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    Apart from a render texture, I think you could use ImmediateModeElement in combination with DrawMeshNow.

    Other than that, maybe there's a creative way to use VisualElement.generateVisualContent, but there's no custom shader support there yet, at least without reflection.
     
  5. ElevenArt

    ElevenArt

    Joined:
    Dec 12, 2012
    Posts:
    16
    Thanks for the answers. Render Texture is a good and simple option.

    Is it necessary to create a Custom Visual Element with this option? With ImmediateModeElement set and DrawMeshNow inside it. Could this also be linked to the data set in the ScriptableObject?
     
  6. oscarAbraham

    oscarAbraham

    Joined:
    Jan 7, 2013
    Posts:
    431
    Yes. As the docs say: "To use this element, create a new element inheriting from this type and override the ImmediateRepaint method."

    Yes. I mean it's your element. In 2023.1 this is easier because you can drag the ScriptableObject into the UI Builder.
     
    ElevenArt likes this.
  7. ElevenArt

    ElevenArt

    Joined:
    Dec 12, 2012
    Posts:
    16
    I think that for using data from Scriptable Objects in UI Toolkit, it would be better to wait for the Data Binding feature. Thanks.