Hot Reload - Call back problems
Hi all. So I recently discovered that Hot Reloading was a thing (I'm pretty new to this). So as an exercise I tried to convert a "drop in" prefab I have written previously. This is a FileBrowser prefab and it operates by calling a static Show() method which instantiates the prefab. In Show() a UnityAction is passed as a callback for when the browser is closed informing the caller. This is causing me headaches to get working with Hot Reload. The first problem is that UnityAction<> is not serializable. so instead I break the action into a method name string and cast the Target property to MonoBehaviour. Both string and MonoBehaviour are serializable. I can then use reflection to invoke the callback. But, this approach is flawed because when a reload occurs the MonoBehaviour I stored for the callback is zombified and this causes a bunch of warnings to show "The referenced script (Unknown) on this Behaviour is missing!" and the callback won't function correctly as it's invoking a method in a zombie object. So, what I'm wanting to do is instead of storing MonoBehaviour, I store the GameObject it is attached to, as that is also serializable. Then at callback I retrieve the MonoBehaviour from the GameObject and use that as the target. The problem I'm having is that I don't see how to get the MonoBehaviour out of the gameobject. The browser can be called from anywhere, so there's no set target type, I could call GetComponent(Type) but I can't store the Type because Type isn't serializable. I tried storing the type as a string then using Type.GetType(string) to retrieve it, but that doesn't seem to work either. Any ideas? Cheers, Marc.
Your answer
Follow this Question
Related Questions
How do I increment a variable while reloading a scene? 1 Answer
Using C# Reflection to get deriving class type from base class (new to reflection) 0 Answers
c# shooting problem (probably pretty simple) 2 Answers
Restart current level after deathscreen 3 Answers
Custom Inspector, NotSupportedException 0 Answers