Arch
                                
                                
                                
                                    Arch copied to clipboard
                            
                            
                            
                        Add Query Unique
We need a method to query singleton components. We will use this method in many scenarios, such as Player Input, making the code look more concise and readable.
    private QueryDescription mDescription = new QueryDescription{Any = new ComponentType[]{typeof(C_PlayerInput)}};
    public void Query()
    {
        world.Query(mDescription, (ref C_PlayerInput input) =>
        {
            if (input.IsClicked)
            {
                //Query another entity....
            }
        });
    }
    public void QueryUnique()
    {
        var playerInput = world.QueryUnique<C_PlayerInput>();
        //Query another entity...
    }
                                    
                                    
                                    
                                
We need a method to query singleton components. We will use this method in many scenarios, such as Player Input, making the code look more concise and readable.
private QueryDescription mDescription = new QueryDescription{Any = new ComponentType[]{typeof(C_PlayerInput)}}; public void Query() { world.Query(mDescription, (ref C_PlayerInput input) => { if (input.IsClicked) { //Query another entity.... } }); } public void QueryUnique() { var playerInput = world.QueryUnique<C_PlayerInput>(); //Query another entity... }
Thanks and that's actually a great idea! :)
Im gonna think about different ways of realizing this. I think combining this with the current Query-API is not possible since that would require checks every call which would result in a decreased performance. However the world.QueryUnique approach is probably fine, so we could set components directly on the world itself.
Im gonna take a look at how other ecs solve this problem, or if they actually solve it at all ^^
We need a method to query singleton components. We will use this method in many scenarios, such as Player Input, making the code look more concise and readable.
private QueryDescription mDescription = new QueryDescription{Any = new ComponentType[]{typeof(C_PlayerInput)}}; public void Query() { world.Query(mDescription, (ref C_PlayerInput input) => { if (input.IsClicked) { //Query another entity.... } }); } public void QueryUnique() { var playerInput = world.QueryUnique<C_PlayerInput>(); //Query another entity... }Thanks and that's actually a great idea! :) Im gonna think about different ways of realizing this. I think combining this with the current
Query-API is not possible since that would require checks every call which would result in a decreased performance. However theworld.QueryUniqueapproach is probably fine, so we could set components directly on the world itself.Im gonna take a look at how other ecs solve this problem, or if they actually solve it at all ^^
The idea of attaching components to the world is an unusual concept. To my knowledge, both Unity ECS and Svelto ECS are attached to entities. Do you want to view the world as a root entity?
Mounting components on the world may produce another way that is independent of the current architecture. Perhaps we need a dictionary with component type as the key and entity as the value. This way, when we call QueryUnique, we can also determine if the component type is unique (singleton) to ensure that user actions do not produce unexpected results.
Mounting components on the world may produce another way that is independent of the current architecture. Perhaps we need a dictionary with component type as the key and entity as the value. This way, when we call QueryUnique, we can also determine if the component type is unique (singleton) to ensure that user actions do not produce unexpected results.
That could work aswell. This could also be a bit optimized by avoiding the dictionary and replacing it with an array for faster access. Dictionarys normally have a small overhead, which is noticeable for large amounts of acess.
I found that the bevy engine use resource for singleton component. the resource stored at spareset.