So I have a game that has runs mostly on audio and decals, but I want all of them to load before even starting the game.
I found out that the preload api is deprecated so I came here to ask
So I have a game that has runs mostly on audio and decals, but I want all of them to load before even starting the game.
I found out that the preload api is deprecated so I came here to ask
PreloadAsync is not deprecated, you could pass {game.Workspace} as the contentIdList argument and it will preload all content which are descendants of it. Audios, decals etc. all added to the request queue.
Sorry if I wasnât clear, as I assume you heard that from me. PreloadAsync is separate from Preload.
Something like this
spawn(function()
game:GetService('ContentProvider'):PreloadAsync({workspace,game:GetService('ReplicatedStorage'),game:GetService('PlayerGui')})
end)
And if you want to make a loading bar
repeat PercentTxt.Text = '('..math.floor(((RequestQueueSize-CP.RequestQueueSize)/RequestQueueSize)* 100)..'%)' LoadingBar:TweenSize(UDim2.new(1 - string.format('%.3f',CP.RequestQueueSize/RequestQueueSize),0,1,0),1,0,.5,true) wait(1) until
CP.RequestQueueSize <= 0
CP = ContentProvider
Itâs just an Example code, donât forget to assign the missing Variables.
I donât recommend relying on RequestQueueSize
for something like a load screen, as assets like shirts from characters will add to this. You may want to use PreloadAsync with 1 asset at a time, like this code snippet from Ultimate Boxingâs preload screen:
for Id,Asset in pairs(OtherAssets) do
local AssetsLeft = #OtherAssets - Id + 1
if AssetsLeft == 1 then
BottomText.Text = "Loading... (1 Asset Left)"
else
BottomText.Text = "Loading... ("..AssetsLeft.." Assets Left)"
end
ContentProvider:PreloadAsync({Asset})
end
to be honest thatâs a really horrible idea, passing workspace to PreloadAsync
first, why are you using game.Workspace
. the global variable workspace
exists and if your workspace gets renamed somehow then your scripts die
second, preloading should only be used on things that need to be seen or heard immediately. itâs not at all recommended you preload your whole game.
Was only using it as an example, no need critisise it like that, if the game is largely asset based then gameplay may be bad without all content loading before entering, I donât think itâs a bad idea at all. I donât like using workspace for some reason, Iâd use game:GetService(âWorkspaceâ) just because of preference.
EDIT: I agree long loading times are bad UX but if itâs to improve gameplay it can be worth it. Take GTA V for example.
Adding on to Generalâs preference, the GetService method operates on class names, not names. If you were to rename any service, getting it by class name still works.
Indexing using service names is not a big deal within places you have control over. âif your workspace gets renamed somehowâ is not a serious concern. Just rename it back. With FilteringEnabled on, exploiters canât rename it on the server either so thatâs not a concern. Service names should be locked anyway, but theyâre not probably for backwards compatibility reasons.
Even in situations where you donât have control over service names â such as in public Modules â you can still use game.Workspace
. Itâs a property and itâs not deprecated. You canât do this with other services though.
I personally believe that using GetService
and using the built in workspace
global variable are good habits, but choosing not to do those things is not a big deal unless youâre writing public modules.
If that is the case then why not just put everything that needs loading into preload first?
And then preload again once loading is done.
@General_Scripter Even in that scenario though, if your game is largely asset based, you should only be preloading what you want immediately visible. Preloading isnât necessarily meant for entire games. You can do what you want with your code, of course, but Iâm just saying based on what I hear and have tried out. I hear your preference, sure, but I do feel that simply writing âworkspaceâ is easier than going the long way to index it in GetService; same goes with game.Workspace for the legacy people (found out itâs a reference property and doesnât directly get the descendant WS, thanks @Corecii).
@Kiansjet Iâm aware. I was speaking in direct relation to game.Workspace
because I forgot/didnât know it was a reference property.
@Corecii Thatâs why Iâm speaking from an all-around point of view, not just owned places. Sometimes even you have to call your own external code in your places. - referring to modules.
Cheers for the replies though.
Yes thats what I exactly what I want to do!
I donât think I have every known someone to have renamed Workspace so it seems pretty irrelevant for you to bring it up. Even if someone DID rename their Workspace, it goes without saying that you canât reference it in scripts anymore, so why you are criticizing his/her comment for thisâŚ?
Jailbreak renames workspace (and a bunch of other stuff) (Security?)
also:
I donât think it was a criticism, more a clash of preferences that came off in a rude manner (which I apologize for, @General_Scripter, if this is what it seemed like).
Perhaps I wasnât clear â my point is that bringing it up is mostly irrelevant and not that people donât do it. Please private message me if you want to continue discussing this.
So waitâŚ
Let me make this clear I could just make a folder and insert all of my important assets and just call them using
game:GetService(âContentProviderâ):PreloadAsync({game.Workspace.AssetThatNeedToBeLoaaded})
??
yeah thatâs right!