-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
0 / 10 of 1 issue completedLabels
A-AssetsLoad files from disk to use for things like images, models, and soundsLoad files from disk to use for things like images, models, and soundsC-FeatureA new feature, making something new possibleA new feature, making something new possibleD-ComplexQuite challenging from either a design or technical perspective. Ask for help!Quite challenging from either a design or technical perspective. Ask for help!M-Needs-Release-NoteWork that should be called out in the blog due to impactWork that should be called out in the blog due to impactS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplishedX-ContentiousThere are nontrivial implications that should be thought throughThere are nontrivial implications that should be thought through
Description
What problem does this solve or what need does it fill?
The current asset system is stored in a single resource Assets
. This means we need a bespoke ID system for assets, events to report changes to assets, different patterns for adding/removing assets, etc.
What solution would you like?
We can unify assets more tightly with the ECS by turning assets into entities.
- Each asset would be an entity holding an
Asset<MyAsset>
component. - AssetIds would just be
Entity
s (or a wrapper aroundEntity
). - Change detection for assets would just be regular component change detection.
- Looking up an asset would just be a regular entity lookup.
- Asset lifetimes can be held in an
AssetLifetime
component. Handles would refer to the same reference count and a system would check for assets with a ref count of 0 to despawn that entity.
Possible issues
- Adding assets is no longer immediate. It requires calling
apply_deferred
(although at least we can get the entity ID immediately so this is not too bad of an issue). - There's nothing stopping users from making "weird" asset entities. For example, one entity with two different asset types. When should the asset be cleaned up? Technically this is fine since as long as you hold handles to the same
AssetLifetime
ref count, it doesn't matter the type. Treating the same entity as a mesh and an image would just be 2 references. - Users can add asset entities without the corresponding systems to manage them. Today, since pretty much all the handling must go through the
Assets
resource, it's fairly hard to have unmanaged assets. Does this matter? For example, you can do weird things without the right systems with events (never clearing, for example). This would just be more of that.
What alternative(s) have you considered?
Keep the system the same. The resource approach is very workable and is pretty nice to use. There are great guard rails (the types are very strong) and it's fairly hard to "break" it.
Additional context
This isn't originally my idea, I'm not sure whose it is though. I just remember hearing about this on Discord and wanted to document this.
kaosat-dev, alice-i-cecile, NyxAlexandra, MalekiRe, te-king and 7 more
Sub-issues
Metadata
Metadata
Assignees
Labels
A-AssetsLoad files from disk to use for things like images, models, and soundsLoad files from disk to use for things like images, models, and soundsC-FeatureA new feature, making something new possibleA new feature, making something new possibleD-ComplexQuite challenging from either a design or technical perspective. Ask for help!Quite challenging from either a design or technical perspective. Ask for help!M-Needs-Release-NoteWork that should be called out in the blog due to impactWork that should be called out in the blog due to impactS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplishedX-ContentiousThere are nontrivial implications that should be thought throughThere are nontrivial implications that should be thought through