Service · inherits Instance
ContentProvider
Service that is used to load content, or assets, into a game.
About ContentProvider
Service that loads content (assets) into a game.
Roblox servers stream all assets to the client at runtime: objects in the Workspace, mesh assets, texture assets, etc. Assets such as mesh visual data, textures, decals, and sounds are streamed in as required, regardless of whether Streaming is enabled.
In some cases, this behavior is undesirable, as it can lead to a delay before the content loads into the experience.
ContentProvider lets you preload assets into an experience using the
ContentProvider.PreloadAsync method. You might want to display a
loading screen, preload critical assets, and only then allow the player into
the experience.
Best Practices for Preloading
- Only preload essential assets, not the entire
Workspace. You might get occasional pop-in, but it decreases load times and generally doesn't disrupt the player experience. Assets that are good candidates for preloading include those required for the loading screen, the UI, or the starting area. - Let players skip the loading screen, or automatically skip it after a certain amount of time.
Properties 2
BaseUrl
: stringReadOnlyNotReplicatedUsed by theContentProviderto download assets from the Roblox website.Used by the
ContentProviderto download assets from the Roblox website.This URL points to a Roblox hosted website from which assets are downloaded and is pulled from the AppSettings.xml file, located in the version-hash folder.
It is possible to overwrite this property using the
ContentProvider.SetBaseUrlfunction in the command bar; however, this is not recommended and may cause asset loading issues.RequestQueueSize
: intReadOnlyNotReplicatedGives the number of items in theContentProviderrequest queue that need to be downloaded.Gives the number of items in the
ContentProviderrequest queue that need to be downloaded.Items are added to the client's request queue when an asset is used for the first time or
ContentProvider.PreloadAsyncis called.Developers are advised not to use RequestQueueSize to create loading bars. This is because the queue size can both increase and decrease over time as new assets are added and downloaded. Developers looking to display loading progress should load assets one at a time (see example below).
Methods 10
GetAssetFetchStatus
(contentId: ContentId) → AssetFetchStatusGets the currentAssetFetchStatusof thecontentIdprovided.Gets the current
AssetFetchStatusof thecontentIdprovided. UseGetAssetFetchStatusChangedSignal()to listen for changes to this value.GetAssetFetchStatusChangedSignal
(contentId: ContentId) → RBXScriptSignalA signal that fires when theAssetFetchStatusof the provided content changes.A signal that fires when the
AssetFetchStatusof the provided content changes. Connect to this signal by using a callback with one argument of typeAssetFetchStatus. This is particularly useful for assets that might update themselves automatically like the thumbnail of a user when they change clothes.ListEncryptedAssets
() → ArrayReturns an array of the asset IDs that currently have a registered encryption key.Returns an array containing every asset ID that currently has an encryption key registered on this
ContentProvider, whether the key was registered directly throughRegisterEncryptedAsset()or throughRegisterSessionEncryptedAsset().The default key set through
RegisterDefaultEncryptionKey()is not included, because it isn't associated with any specific asset.PreloadAsync
(contentIdList: Array, callbackFunction: Function = nil) → ()YieldsYields until all of the assets associated with the givenInstanceshave loaded.Yields until all of the assets associated with the given
Instanceshave loaded. This can be used to pause a script and not use content until it is certain that the content has been loaded into the experience.When called, the engine identifies links to content for each item in the list. For any of the
Instanceswhich have properties that define links to content, such as aDecalor aSound, the engine attempts to load these assets from Roblox. For each requested asset, the callback function runs, indicating the asset's finalAssetFetchStatus.If any of the assets fail to load, an error message appears in the output. The method itself will not error and it will continue executing until it has processed each requested instance.
Limitations
SurfaceAppearanceandMaterialVariantare not supported byPreloadAsync()because these objects rely on processed texture pack assets rather than directly loading individual textures. Calling it on aSurfaceAppearanceinstance will not do anything, but the associated textures will still be streamed in during runtime.If PreloadAsync is called on
Instancesthat are not currently visible, such as aDecalor anImageLabel, the Engine will download and store textures used by those Instances in its disk cache. Because theInstancesare not visible in these cases, the Engine may reduce memory consumption by unloading the textures after preloading them.RegisterDefaultEncryptionKey
(encryptionKey: string) → ()Registers a fallback encryption key used to decrypt any encrypted asset that doesn't have its own key registered.Sets a fallback encryption key that the
ContentProvideruses to decrypt any encrypted asset that isn't matched by a key registered for a specific asset throughRegisterEncryptedAsset(). When an asset is fetched, the engine first looks for a key registered for that asset's ID; if none exists, it falls back to this default key.RegisterDefaultSessionKey
(sessionKey: string) → ()Decrypts the provided session key and registers the result as the default encryption key.Decrypts
sessionKeyusing the session's cryptographic context and then registers the decrypted result as the default encryption key, exactly asRegisterDefaultEncryptionKey()does. Use this variant when the key is delivered to the client in session-encrypted form rather than as plaintext.RegisterEncryptedAsset
(assetId: ContentId, encryptionKey: string) → ()Registers an encryption key used to decrypt a specific encrypted asset.Associates
encryptionKeywith the givenassetIdso that, when theContentProviderfetches that asset, it uses the key to decrypt the downloaded file. A key registered for a specific asset takes precedence over the default key set throughRegisterDefaultEncryptionKey(). The method throws an error ifassetIdisn't a valid asset ID.RegisterSessionEncryptedAsset
(contentId: ContentId, sessionKey: string) → ()Decrypts the provided session key and registers it as the encryption key for a specific asset.Decrypts
sessionKeyusing the session's cryptographic context and then registers the decrypted result as the encryption key forcontentId, exactly asRegisterEncryptedAsset()does. Use this variant when the per-asset key is delivered to the client in session-encrypted form rather than as plaintext.UnregisterDefaultEncryptionKey
() → ()Clears the default encryption key previously set on theContentProvider.Removes the default encryption key registered through
RegisterDefaultEncryptionKey(), so that assets without a specifically registered key are no longer decrypted with a fallback key. Keys registered for individual assets throughRegisterEncryptedAsset()are unaffected.UnregisterEncryptedAsset
(assetId: ContentId) → ()Removes the encryption key registered for a specific asset.Removes the encryption key associated with
assetIdbyRegisterEncryptedAsset(), so the asset is no longer decrypted with that key. If no key is registered for the asset, the call has no effect.
Events 1
AssetFetchFailed
ContentProvider.AssetFetchFailed:Connect(function(assetId))Fires when theContentProviderfails to fetch an asset, passing the asset's ID.Fires when an asset requested through the
ContentProviderfails to be fetched, passing the content ID of the asset that failed.
ContentProvider also has every member of Instance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.