Rbxgameasset and PreloadAsync

I have scanned a lot of the developer forum, and I cannot seem to find a solution to this. And it is unclear on the API Reference page…

Does this work? Can I just use an rbxgameasset://NAME id with PreloadAsync? (Sorry if this is a little vague or obscure)

As of August 31st, 2017, ContentProvider:PreloadAsync() was enabled in favor of ContentProvider:Preload().

PreloadAsync takes a list of instances. If a string is used instead, it will be assumed to be an image otherwise the request will error.

local sound1 = Instance.new("Sound")
sound1.SoundId = "rbxassetid://some sound id"
sound1.Parent = game.Workspace

local sound2 = Instance.new("Sound")
sound2.SoundId = "rbxassetid://some other id"
sound2.Parent = game.Workspace

local instancesToLoad = {sound1, sound2, "rbxassetid://some image id"}

game:GetService("ContentProvider"):PreloadAsync(instancesToLoad)

To answer your question, anything that is not an image must be passed through as it’s own instance.

1 Like

No, you can’t do this actually unless you manually maintain a Folder in the DataModel containing such assets. There is no way to fetch rbxgameasset ids.

Preload and PreloadAsync always existed in parallel. Preload was used to load singular assets, while PreloadAsync accepted a table of strings. In accordance with the material from that thread, Preload was ditched (and thankfully so), while PreloadAsync was changed to accept Instances as parameters.

Despite the fact that PreloadAsync still accepts strings as values to be passed into PreloadAsync to make it backwards compatible for its former behaviour and because many games started using this before the behaviour was changed, I wouldn’t rely on automatic coercion of strings to the image asset type. It’s good practice to keep your arguments uniform where necessary - in this case, passing only Instances and not including any strings.

1 Like

Thanks!

1 Like