-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Component methods not passed from C# to globals #28
Comments
I am not sure but I think your classes need to be public. Otherwise none of the methods should be passed to the Javascript side. |
Hm no I don't think that's right. In my example the |
Non-public classes and methods may work in Here is the test covering this case. It seems to work in Build/Editor, ClearScript/Jint and all platforms. Let me know if there is any difference in your code and what I am testing, or something else that may be causing the problem. |
Ok this also appears to be working now. It didn't work immediately so there still might be some issue remaining but it could have just been me doing something silly. In any case I can't reproduce the problem anymore. I'll keep an eye on it. |
Don't forget that the changes on Globals can still take at least 1 frame to update on React side. The way to prevent that is by doing the changes before React first renders. Closing this. |
Turns out that whether a method on an object gets passed from C# to Javascript via the globals mechanism depends on what the object's class is.
In particular, methods on a
MonoBehaviour
object are not passed through, though equivalent methods on a class that derives directly fromUnityEngine.Object
are passed through. I initially thought it was simply a matter of the object needing to be aUnityEngine.Object
, butMonoBehaviour
also derives fromUnityEngine.Object
so it's not just that.Not sure if this is a React Unity issue or just an issue of
MonoBehaviour
doing something unexpected.Example:
React:
The logs will say
The text was updated successfully, but these errors were encountered: