#Adaptive Performance
1 messages · Page 1 of 1 (latest)
Okay, so my first issue is that the null ref was getting hit because it looks like I should have been calling Holder.Initialize() instead of Holder.Instance?.InitializeAdaptivePerformance()
Still not seeing meaningful data however, so I'm continuing to investigate
Good news, I got it working! Basically, it looks the instance on launch was getting destroyed by some other system on scene transition. As a result, Holder.Instance was not null, but the manager game object was unavailable to return any metrics. Meanwhile, my attempts in the interim to re-initialize it weren't working because it was early exiting on Holder.Instance != null. To get around that, I updated the code such that, when it detects that Adaptive Performance is not initialized, it first calls Holder.Deinitialize() (which actually clears Instance) and then immediately calling Holder.Initialize() 🎉
Good you solved it! The null coalesce operator is not usable with unity objects as it bypasses the Object.Equals() override that makes unity objects equate to null when destroyed.
Also dont forget about RuntimeInitializeOnLoad if you need to init things on app start but want to avoid using a monobehaviour to do it
@twilit sail ^
Hey Rob, it's me, Rob 😄 Thanks for the tips! To clarify, the null conditional in my 2nd message was just shorthand for the expanded code referenced in the 1st, so I don't expect that to have been an issue here, but that's definitely good to keep in mind! Using RuntimeInitializeOnLoad is a good callout, especially since in this case, we've got static methods on the C# side providing access to functionality within our Lua runtime code, where we're not often in the habit of using monobehaviours. And yeah, in fact the attribute [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] was part of how I was able to validate that AP was working at least on launch initially. Admittedly, it's not something I've used often before, but I think I'll have to look out for more opportunities to do so, as it feels quite handy. Thanks for the feedback!
No problem Rob 👋