Search Results for

    Show / Hide Table of Contents

    Binding Elements


    Evergine allows to bind dependencies automatically across your components, services and sceneManagers.

    For example, bindings allow a custom component to require that its Owner Entity has a Transform3D component, and set it to a property during the Attach phase (see the Lifecycle documents)

    This binding feature gives to developers a lot of flexibility to interconnect components, services and scene managers, avoiding the tedious part to setup this dependencies in Evergine Studio or from code.

    In Evergine, we define bindings using property attributes ([BindComponent] for example).

    Note

    All dependencies are not available until the Attach phase, if you try to access during in the constructor, OnLoaded() or OnDestroy() methods, the property value is goint to be null

    In this section

    There are four types of binding:

    • Bind Components
    • Bind Services
    • Bind Entities
    • Bind SceneManagers

    Example

    In the following example, the component will bind a service, a component an a scene manager.

    public class MyComponent : Component
    {
        [BindService]
        private AssetsService assetsService;
    
        [BindSceneManager]
        private RenderManager renderManager;
    
        [BindComponent]
        private Transform3D transform;
    
        private Material defaultMaterial;
    
        protected override Start()
        {
            // All values of bind attributes will be injected after the Attach phase...
            
            // Bind assetService
            this.defaultMaterial = this.assetsService.Load<Material>(EvergineContent.Materials.DefaultMaterial);
            
            // Bind SceneManagers
            this.RenderManager.DebugLines = true;
            
            // Bind Components
            this.transform.Position = Vector3.Zero;
        }
    
        // ... 
    }
    

    Bind Collections

    If the [Bind] attribute is set on top of List<T> property, they will attempt to search a list of elements that elements that satisfy the dependency:

    // Bind with the Transform component of the owner entity...
    [BindComponent]
    private Transform3D transform;
    
    // Bind a list with all Camera3D components of the entire scene...
    [BindComponent(source: BindComponentSource.Scene)]
    private List<Camera3D> sceneCameras;
    
    In This Article
    Back to top
    Generated by DocFX