So I have a problem with my addon whenever I log in after the cache has been deleted; major patches also seem to invalidate the cache such that I hit the same problem. I'm calling the function GetCompanionInfo, but in this scenario, the creatureName is being returned as nil and this messes up my addon. Reloading UI fixes the problem, but that's an annoyance and confusing to users who don't know what's going on.
I'm doing this initialization during OnEnable and my question is whether there's a better time/place I should be doing this kind of addon initialization.
Currently, my only other alternative is to try delay init until one of my methods is called. With that approach I'd also have to catch when the options UI is brought up, in case that is done before any methods are called (because those strings are needed to populate some dropdowns). I'm using wowace's options functionality, what can I hook there to tell that the options for my addon are about to be shown?
you might try looking at the COMPANION_UPDATE event. trade skills have the same problem where you ask about them and get nils if they're not cached. when they do eventually make it into the cache, an update event is called. i suspect the COMPANION_UPDATE would probably function in a like manner. you just need to trap the nil and make sure it doesn't wreck your system, then have the COMPANION_UPDATE event force a "rescan" of your companion data.