Trait bevy::prelude::Resource

source ·
pub trait Resource: Send + Sync + 'static { }
Expand description

A type that can be inserted into a World as a singleton.

You can access resource data in systems using the Res and ResMut system parameters

Only one resource of each type can be stored in a World at any given time.

Examples

#[derive(Resource)]
struct MyResource { value: u32 }

world.insert_resource(MyResource { value: 42 });

fn read_resource_system(resource: Res<MyResource>) {
    assert_eq!(resource.value, 42);
}

fn write_resource_system(mut resource: ResMut<MyResource>) {
    assert_eq!(resource.value, 42);
    resource.value = 0;
    assert_eq!(resource.value, 0);
}

!Sync Resources

A !Sync type cannot implement Resource. However, it is possible to wrap a Send but not Sync type in SyncCell or the currently unstable Exclusive to make it Sync. This forces only having mutable access (&mut T only, never &T), but makes it safe to reference across multiple threads.

This will fail to compile since RefCell is !Sync.


#[derive(Resource)]
struct NotSync {
   counter: RefCell<usize>,
}

This will compile since the RefCell is wrapped with SyncCell.

use bevy_utils::synccell::SyncCell;

#[derive(Resource)]
struct ActuallySync {
   counter: SyncCell<RefCell<usize>>,
}

Implementors§

source§

impl Resource for AssetMetaCheck
where AssetMetaCheck: Send + Sync + 'static,

source§

impl Resource for ScreenSpaceTransmissionQuality

source§

impl Resource for Msaa
where Msaa: Send + Sync + 'static,

source§

impl Resource for TimeUpdateStrategy
where TimeUpdateStrategy: Send + Sync + 'static,

source§

impl Resource for AccessibilityRequested
where AccessibilityRequested: Send + Sync + 'static,

source§

impl Resource for Focus
where Focus: Send + Sync + 'static,

source§

impl Resource for ManageAccessibilityUpdates

source§

impl Resource for FixedMainScheduleOrder
where FixedMainScheduleOrder: Send + Sync + 'static,

source§

impl Resource for MainScheduleOrder
where MainScheduleOrder: Send + Sync + 'static,

source§

impl Resource for EmbeddedAssetRegistry
where EmbeddedAssetRegistry: Send + Sync + 'static,

source§

impl Resource for AssetSourceBuilders
where AssetSourceBuilders: Send + Sync + 'static,

source§

impl Resource for AssetProcessor
where AssetProcessor: Send + Sync + 'static,

source§

impl Resource for AssetServer
where AssetServer: Send + Sync + 'static,

source§

impl Resource for DefaultSpatialScale
where DefaultSpatialScale: Send + Sync + 'static,

source§

impl Resource for GlobalVolume
where GlobalVolume: Send + Sync + 'static,

source§

impl Resource for FrameCount
where FrameCount: Send + Sync + 'static,

source§

impl Resource for BlitPipeline
where BlitPipeline: Send + Sync + 'static,

source§

impl Resource for CASPipeline
where CASPipeline: Send + Sync + 'static,

source§

impl Resource for FxaaPipeline
where FxaaPipeline: Send + Sync + 'static,

source§

impl Resource for TonemappingLuts
where TonemappingLuts: Send + Sync + 'static,

source§

impl Resource for TonemappingPipeline
where TonemappingPipeline: Send + Sync + 'static,

source§

impl Resource for DiagnosticsStore
where DiagnosticsStore: Send + Sync + 'static,

source§

impl Resource for AppTypeRegistry
where AppTypeRegistry: Send + Sync + 'static,

source§

impl Resource for MainThreadExecutor
where MainThreadExecutor: Send + Sync + 'static,

source§

impl Resource for Schedules
where Schedules: Send + Sync + 'static,

source§

impl Resource for Stepping
where Stepping: Send + Sync + 'static,

source§

impl Resource for GizmoConfigStore
where GizmoConfigStore: Send + Sync + 'static,

source§

impl Resource for GamepadSettings
where GamepadSettings: Send + Sync + 'static,

source§

impl Resource for Gamepads
where Gamepads: Send + Sync + 'static,

source§

impl Resource for Touches
where Touches: Send + Sync + 'static,

source§

impl Resource for DeferredLightingLayout
where DeferredLightingLayout: Send + Sync + 'static,

source§

impl Resource for AmbientLight
where AmbientLight: Send + Sync + 'static,

source§

impl Resource for DefaultOpaqueRendererMethod

source§

impl Resource for DirectionalLightShadowMap
where DirectionalLightShadowMap: Send + Sync + 'static,

source§

impl Resource for FogMeta
where FogMeta: Send + Sync + 'static,

source§

impl Resource for GlobalLightMeta
where GlobalLightMeta: Send + Sync + 'static,

source§

impl Resource for GlobalVisiblePointLights
where GlobalVisiblePointLights: Send + Sync + 'static,

source§

impl Resource for LightMeta
where LightMeta: Send + Sync + 'static,

source§

impl Resource for LightProbesBuffer
where LightProbesBuffer: Send + Sync + 'static,

source§

impl Resource for MeshBindGroups
where MeshBindGroups: Send + Sync + 'static,

source§

impl Resource for MeshPipeline
where MeshPipeline: Send + Sync + 'static,

source§

impl Resource for PointLightShadowMap
where PointLightShadowMap: Send + Sync + 'static,

source§

impl Resource for PrepassViewBindGroup
where PrepassViewBindGroup: Send + Sync + 'static,

source§

impl Resource for PreviousViewProjectionUniforms

source§

impl Resource for RenderLightmaps
where RenderLightmaps: Send + Sync + 'static,

source§

impl Resource for RenderMeshInstances
where RenderMeshInstances: Send + Sync + 'static,

source§

impl Resource for ShadowSamplers
where ShadowSamplers: Send + Sync + 'static,

source§

impl Resource for SkinUniform
where SkinUniform: Send + Sync + 'static,

source§

impl Resource for WireframeConfig
where WireframeConfig: Send + Sync + 'static,

source§

impl Resource for ClearColor
where ClearColor: Send + Sync + 'static,

source§

impl Resource for ManualTextureViews
where ManualTextureViews: Send + Sync + 'static,

source§

impl Resource for SortedCameras
where SortedCameras: Send + Sync + 'static,

source§

impl Resource for DeterministicRenderingConfig

source§

impl Resource for GlobalsBuffer
where GlobalsBuffer: Send + Sync + 'static,

source§

impl Resource for GlobalsUniform
where GlobalsUniform: Send + Sync + 'static,

source§

impl Resource for RenderAppChannels
where RenderAppChannels: Send + Sync + 'static,

source§

impl Resource for RenderGraph
where RenderGraph: Send + Sync + 'static,

source§

impl Resource for PipelineCache
where PipelineCache: Send + Sync + 'static,

source§

impl Resource for RenderAdapter
where RenderAdapter: Send + Sync + 'static,

source§

impl Resource for RenderAdapterInfo
where RenderAdapterInfo: Send + Sync + 'static,

source§

impl Resource for RenderDevice
where RenderDevice: Send + Sync + 'static,

source§

impl Resource for RenderInstance
where RenderInstance: Send + Sync + 'static,

source§

impl Resource for RenderQueue
where RenderQueue: Send + Sync + 'static,

source§

impl Resource for MainWorld
where MainWorld: Send + Sync + 'static,

source§

impl Resource for DefaultImageSampler
where DefaultImageSampler: Send + Sync + 'static,

source§

impl Resource for FallbackImage
where FallbackImage: Send + Sync + 'static,

source§

impl Resource for FallbackImageCubemap
where FallbackImageCubemap: Send + Sync + 'static,

source§

impl Resource for FallbackImageFormatMsaaCache

source§

impl Resource for FallbackImageZero
where FallbackImageZero: Send + Sync + 'static,

source§

impl Resource for TextureCache
where TextureCache: Send + Sync + 'static,

source§

impl Resource for ExtractedWindows
where ExtractedWindows: Send + Sync + 'static,

source§

impl Resource for ViewUniforms
where ViewUniforms: Send + Sync + 'static,

source§

impl Resource for WindowSurfaces
where WindowSurfaces: Send + Sync + 'static,

source§

impl Resource for ScreenshotManager
where ScreenshotManager: Send + Sync + 'static,

source§

impl Resource for ScreenshotToScreenPipeline

source§

impl Resource for SceneSpawner
where SceneSpawner: Send + Sync + 'static,

source§

impl Resource for ExtractedSprites
where ExtractedSprites: Send + Sync + 'static,

source§

impl Resource for ImageBindGroups
where ImageBindGroups: Send + Sync + 'static,

source§

impl Resource for Mesh2dBindGroup
where Mesh2dBindGroup: Send + Sync + 'static,

source§

impl Resource for Mesh2dPipeline
where Mesh2dPipeline: Send + Sync + 'static,

source§

impl Resource for RenderMesh2dInstances
where RenderMesh2dInstances: Send + Sync + 'static,

source§

impl Resource for SpriteAssetEvents
where SpriteAssetEvents: Send + Sync + 'static,

source§

impl Resource for SpriteMeta
where SpriteMeta: Send + Sync + 'static,

source§

impl Resource for SpritePipeline
where SpritePipeline: Send + Sync + 'static,

source§

impl Resource for FontAtlasSets
where FontAtlasSets: Send + Sync + 'static,

source§

impl Resource for TextPipeline
where TextPipeline: Send + Sync + 'static,

source§

impl Resource for TextSettings
where TextSettings: Send + Sync + 'static,

source§

impl Resource for TimeReceiver
where TimeReceiver: Send + Sync + 'static,

source§

impl Resource for TimeSender
where TimeSender: Send + Sync + 'static,

source§

impl Resource for ExtractedUiNodes
where ExtractedUiNodes: Send + Sync + 'static,

source§

impl Resource for UiImageBindGroups
where UiImageBindGroups: Send + Sync + 'static,

source§

impl Resource for UiMeta
where UiMeta: Send + Sync + 'static,

source§

impl Resource for UiPipeline
where UiPipeline: Send + Sync + 'static,

source§

impl Resource for UiScale
where UiScale: Send + Sync + 'static,

source§

impl Resource for UiStack
where UiStack: Send + Sync + 'static,

source§

impl Resource for UiSurface
where UiSurface: Send + Sync + 'static,

source§

impl Resource for WinitActionHandlers
where WinitActionHandlers: Send + Sync + 'static,

source§

impl Resource for WinitSettings
where WinitSettings: Send + Sync + 'static,

source§

impl<A> Resource for Assets<A>
where A: Asset, Assets<A>: Send + Sync + 'static,

source§

impl<A> Resource for ExtractedAssets<A>
where A: RenderAsset, ExtractedAssets<A>: Send + Sync + 'static,

source§

impl<A> Resource for PrepareNextFrameAssets<A>
where A: RenderAsset, PrepareNextFrameAssets<A>: Send + Sync + 'static,

source§

impl<A> Resource for RenderAssets<A>
where A: RenderAsset, RenderAssets<A>: Send + Sync + 'static,

source§

impl<C> Resource for ComponentUniforms<C>
where C: Component + ShaderType, ComponentUniforms<C>: Send + Sync + 'static,

source§

impl<E> Resource for Events<E>
where E: Event, Events<E>: Send + Sync + 'static,

source§

impl<EI> Resource for ExtractedInstances<EI>
where EI: ExtractInstance, ExtractedInstances<EI>: Send + Sync + 'static,

source§

impl<M> Resource for ExtractedMaterials<M>
where M: Material, ExtractedMaterials<M>: Send + Sync + 'static,

source§

impl<M> Resource for MaterialPipeline<M>
where M: Material, MaterialPipeline<M>: Send + Sync + 'static,

source§

impl<M> Resource for PrepassPipeline<M>
where M: Material, PrepassPipeline<M>: Send + Sync + 'static,

source§

impl<M> Resource for ExtractedMaterials2d<M>
where M: Material2d, ExtractedMaterials2d<M>: Send + Sync + 'static,

source§

impl<M> Resource for Material2dPipeline<M>
where M: Material2d, Material2dPipeline<M>: Send + Sync + 'static,

source§

impl<M> Resource for RenderMaterial2dInstances<M>
where M: Material2d, RenderMaterial2dInstances<M>: Send + Sync + 'static,

source§

impl<M> Resource for ExtractedUiMaterialNodes<M>
where M: UiMaterial, ExtractedUiMaterialNodes<M>: Send + Sync + 'static,

source§

impl<M> Resource for ExtractedUiMaterials<M>
where M: UiMaterial, ExtractedUiMaterials<M>: Send + Sync + 'static,

source§

impl<M> Resource for UiMaterialMeta<M>
where M: UiMaterial, UiMaterialMeta<M>: Send + Sync + 'static,

source§

impl<M> Resource for UiMaterialPipeline<M>
where M: UiMaterial, UiMaterialPipeline<M>: Send + Sync + 'static,

source§

impl<P> Resource for DrawFunctions<P>
where P: PhaseItem, DrawFunctions<P>: Send + Sync + 'static,

source§

impl<S> Resource for NextState<S>
where S: States, NextState<S>: Send + Sync + 'static,

source§

impl<S> Resource for State<S>
where S: States, State<S>: Send + Sync + 'static,

source§

impl<S> Resource for SpecializedComputePipelines<S>

source§

impl<S> Resource for SpecializedMeshPipelines<S>

source§

impl<S> Resource for SpecializedRenderPipelines<S>

source§

impl<T> Resource for GpuArrayBuffer<T>
where T: GpuArrayBufferable, GpuArrayBuffer<T>: Send + Sync + 'static,

source§

impl<T> Resource for ReportHierarchyIssue<T>
where ReportHierarchyIssue<T>: Send + Sync + 'static,

source§

impl<T> Resource for Axis<T>
where Axis<T>: Send + Sync + 'static,

source§

impl<T> Resource for ButtonInput<T>
where T: Copy + Eq + Hash + Send + Sync + 'static, ButtonInput<T>: Send + Sync + 'static,

source§

impl<T> Resource for RenderMaterials<T>
where T: Material, RenderMaterials<T>: Send + Sync + 'static,

source§

impl<T> Resource for RenderMaterials2d<T>
where T: Material2d, RenderMaterials2d<T>: Send + Sync + 'static,

source§

impl<T> Resource for Time<T>
where T: Default, Time<T>: Send + Sync + 'static,

source§

impl<T> Resource for RenderUiMaterials<T>
where T: UiMaterial, RenderUiMaterials<T>: Send + Sync + 'static,