What situations would we need to use craft.renderer for?

I’m learning Craft and can’t figure out what craft.renderer is needed for. The reference manual indicates you can add a craft.renderer component to an entity in your scene and then add models and materials to the craft.renderer component. However, it seems easier to bypass using the craft.renderer component and just add the models and materials directly to an entity you created in your scene.

Could someone explain in what situations one might want to add a craft.renderer component to their entity?

Thanks :slight_smile:

@SugarRay craft.renderer is the component that stores your model as part of the rendering system. entity.model and entity.material are actually shortcuts for setting up a renderer. There are some additional methods and properties you can access in the renderer itself, such as:

  • renderer.mask - Rendering mask, complement to camera.mask for filtering entity rendering
  • renderer.instances - The number of instances of the model to render (combine with gl_InstanceID in shaders or the Instance ID node in shade
  • renderer:getMaterial(i) & renderer:setMaterial(i, mat) - Get and set material at index i, use for models with multiple materials (override existing material)

Thanks for the explanation, @John!