Should we change the balance to a LazyValue in case of a race condition?

Hi there, I’m finishing up with the Shop part of the fourth RPG course.

On the Purse script, we initialize the balance on Awake, and then on Restore State we initialize it again from the saved value. Is there a risk of a Race Condition here? And if so, should we change it to a Lazy Value? I remember we did something similar with the health value on the Health script.

Thanks!

For testing purposes, we’re setting that initial value in Awake to a non-zero value, but in practice, you’re generally going to be leaving that value at 0. We’re also only accessing it for the UI and to use within the Shop, so it should well and truly be updated before then.

Not saying you can’t use a LazyValue, but under most circumstances, it’s unlikely to be necessary.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms