Pharan

I often need references to SkeletonAnimation's state and skeleton instances. But because of some Unity lifecycle stuff in special circumstances (like when you instantiate GameObjects from prefabs), they don't always get initialized before I need them.

I've tried calling Initialize myself but as it is (since the null guard is in Update and not in Initialize itself) there's a chance the state and skeleton references to already-initialized objects get overwritten and I get some really freaky behavior as a result.

So I've found it useful to add a separate SafeInitialize() method to SkeletonComponent with a null guard in it before calling Initialize().
I dunno if this is good form in terms of API (and I can't think of a better name for the method).

I've considered making properties (that sort of does lazy-instantiation-but-not-really itself) for skeleton and state too, but it seemed simpler to me to keep Initialization centralized like it already is.

I'd like some input from other Spine-Unity users too as to what a good alternate solution would be or if I should just stick with this.

Mostly, I just want to know if it makes sense to add to official Spine-Unity so I don't have to re-add the darned thing in every update. Or worse, add it to every class in my project that needs the SafeInitialize functionality.

Then we can do a PR on github and Nate can approve it. *has no idea how open-source projects handle this sort of thing*
Аватара пользователя
Pharan
  • Сообщения: 5366

Nate

Generally you just make changes, submit a PR describing why you want it, and whoever is managing the OSS project decides if it goes in.

I've made Initialize safe to be called at any time. The check is still in Update to avoid a method call since most of the time Initialize is not needed.

Isn't there a better way to control the order things happen in Unity so you don't need to manually initialize gameobjects?
Аватара пользователя
Nate

Nate
  • Сообщения: 9766


Вернуться в Runtimes