Does window.dispatchReactUnityEvent() return a value? #539
-
Hi, I have yet to upgrade from v8 to v9 for my project at work and I'm currently evaluating the impact it would have on our codebases before we try the upgrade. One thing that doesn't seem clear is whether the For example, here is some redacted v8 code: mergeInto(LibraryManager.library, {
GetElectricalCodeJS: function() {
var returnStr = ReactUnityWebGL.GetElectricalCode();
var bufferSize = lengthBytesUTF8(returnStr) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(returnStr, buffer, bufferSize);
return buffer;
},
}); This code allows Unity to get a value from React. We have multiple functions like this and it's not clear if the following v9 code will work: mergeInto(LibraryManager.library, {
GetElectricalCodeJS: function() {
var returnStr = window.dispatchReactUnityEvent("GetElectricalCode");
var bufferSize = lengthBytesUTF8(returnStr) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(returnStr, buffer, bufferSize);
return buffer;
},
}); To be clear, the If anyone can answer, it would be greatly appreciated. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think I answered my own question by looking at the actual code for const dispatchReactUnityEvent = (
eventName: string,
...parameters: ReactUnityEventParameter[]
): ReactUnityEventParameter => {
// Loops through all of the mounted event systems and dispatches the event.
// In case there are multiple event systems, the return value origin is
// undefined.
let returnValue: ReactUnityEventParameter = undefined;
mountedEventDispatchers.forEach((dispatchEvent) => {
returnValue = dispatchEvent(eventName, ...parameters);
});
return returnValue;
}; Should have an example for this in the docs. |
Beta Was this translation helpful? Give feedback.
I think I answered my own question by looking at the actual code for
dispatchReactUnityEvent
. Doh!Should have an example for this in the docs.