#OK, I think I'm nearly there. There's an
1 messages ยท Page 1 of 1 (latest)
I wouldn't use a while loop like you have done. Instead, I would use async functions and await their execution. Here is simple example (without error handling) that should show you what I mean https://docs.unity.com/ugs/en-us/manual/cloud-save/manual/tutorials/unity-sdk#End_to_end_initialization_and_authentication_flow
Notice that the steps are
- Initialize the UnityServices
- Sign the player in
- Load data from cloud save
OK, just to clarify - I do this (In my Sign In script), but these scripts are seperate, and trying to get that data for other stuff.
The issue I'm having, is waiting until that process (sign in) has been completed.
Is there a better way to wait, instead of the while loop?
So my flow is three scripts:
UGSAccounts (Sign in)
UGSCloudSaves (Cloud)
BootManager (Manages the Main Menu)
UGS Accounts awaits InitialiseAsync, it then awaits SignInAnonymouslyAsync.
BootManager holds an AuthStateChanged function, it will not do anything until the player signs in and that pings.
UGSCloudSaves does nothing, it is called by BootManager.
But still, somehow, CloudSaves doesn't seem to be ready (even though it awaits the IsSignedIn), which the BootManager is also triggered by.
Ah I see - in that case I would recommend using an event system that will emit a message that other scripts can receive. This will allow you to decouple the scripts from each other. Here is a pretty good video on the topic https://www.youtube.com/watch?v=7_dyDmF0Ktw
Let's build the ultimate event system in Unity. With just 2 Scripts, you'll improve your programming skills and be able to organise and decouple your code much better! Less spaghetti code and more independent systems!
โ
Join the Kingdom:
https://discord.gg/M2qfnUGxAz
โ
Download the 2 epic scripts here: https://www.gamedev.lu/game-assets
โ
Wat...
Alrighty, this makes sense! Thanks Francois, I appreciate you taking the time to help me with this.
no problem!
the way you originally wrote this is @agile hound makes more sense, than the burdensome event whatever... the ugs functionality is materially decoupled from the rest of your game, so it makes sense that they are eventually consistent and you do the right thing
It doesn't work though. ๐ I eventually replaced the async tasks with IENumerators.
I don't know if I had to many await chains or what, code just wasn't firing in the sequence it should.
Instead, I added a horrible wait for X seconds between UGS functions, that works fine.