Skip to content

Allow users to blend &mut World with other system parameters using a "scoped World" pattern #4158

@alice-i-cecile

Description

@alice-i-cecile

What problem does this solve or what need does it fill?

The hard line between exclusive and non-exclusive systems results in very frustrating UX: users must learn a whole new API with complex borrow-checking rules in order to access the world.

Many convenient, ergonomic APIs (like EventReader) must be manually reimplemented or worked around, encouraging code duplication both within the engine and in user code.

What solution would you like?

  1. Other system parameters can coexist with &mut World.
  2. Conflicts are checked on the basis of these other system parameters.
  3. The World returned by &mut World is incomplete: any data required by other system parameters is removed from it for the duration of the system.
  4. Under the hood, this uses resource_scope and other parallel APIs.

Status

This is a large task, and should be done in a piecemeal fashion.

As a result, it seems like there's a split between "scopable" and "non-scopable" system parameters, that we should probably try to reflect in the type system somehow.

What alternative(s) have you considered?

WorldCell is an API that exists largely to get around this pain. #3939 proposes removing it completely, due to its limitations and runtime-panicking nature.

#4090 also attempts to relieve this pain, but there are some things that genuinely require &mut World access.

Additional context

Dissolving the boundaries between exclusive and regular (FunctionSystem) systems is one of the incidental goals behind the Stageless RFC. This design would help further that process.

#4157 is a necessary step to allow us to extend this work to queries (and hence entity-component data).

This is likely to be useful when working with e.g. saving the game, working with scenes or networking, as we commonly want to operate on a massive scale across the whole world, except for some data that is used for coordinating the task.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions