Search Unity

Changing material in Tiny

Discussion in 'Project Tiny' started by Maras, Dec 26, 2019.

  1. Maras

    Maras

    Joined:
    Dec 11, 2012
    Posts:
    88
    If I understand correctly there are two mesh renderers - one for Hybrid renderer (Unity.Rendering.RenderMesh) and one for Tiny DOTS renderer (Unity.Tiny.Rendering.MeshRenderer). If I would want to change the material of an entity, I would have to create two systems and two authoring tools. One for the editor and one for runtime.
    Is that correct? Is this something that will be addressed in the future?

    For the Tiny renderer, does each material has a component with type SimpleMaterial by default and swapping it changes the material?

    Thanks!
     
  2. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    48
    Hi Maras,
    That is correct you need two systems if you want to use the hybrid renderer in Playmode. But it's not required if you are targeting the Dot runtime and if you will not use the Playmode at all for your iteration.

    What you will need is the following:
    1- On the mesh renderer entity you mush add DynamicMaterial in order for the rendering system to update the mesh material.
    2- Get the MeshRenderer and replace the material entity with the new one.
    Just follow how we are updating the UI materials in TinyRacing
    - Adding dynamic material
    - Update the Material entity
     
    Maras likes this.
  3. Maras

    Maras

    Joined:
    Dec 11, 2012
    Posts:
    88
    I can't really imagine a workflow without a play mode anymore, I will just create two systems then. :)

    I missed the DynamicMaterial requirements, thanks!

    Does each MeshRenderer have it's own SimpleMaterial by default during Tiny runtime and is that what I should update?
     
  4. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    48
    The editor automatically adds URP Lit material to mesh renderers by default, this Lit material is converted and used by the Dots runtime.
    Also, keep in mind that this material is shared across mesh renderers.
    In your case, it's better to create a new URP lit material asset in the editor, create an authoring component to convert it and then update the MeshRenderer with the new material.
     
  5. Maras

    Maras

    Joined:
    Dec 11, 2012
    Posts:
    88

    Yeah, I thought it works this way.

    I just do not really get how the component SimpleMaterial fits in - it seems like a component that each material entity has during Tiny runtime. Is that so?
     
    Last edited: Dec 26, 2019
  6. AbdulAlgharbi

    AbdulAlgharbi

    Unity Technologies

    Joined:
    Jul 27, 2018
    Posts:
    48
    Not each material entity but depends on what material type you are using on your game object in the scene.
    There are two components that the material entity can have in the runtime either:
    SimpleMaterial is added if you are using URP Unlit material
    LitMaterial is added if you are using URP Lit material
     
    Maras likes this.
unityunity