Reputation: 2633
I want to call a unity webgl function from a vue website, in order to do this I have the following javascript/vue code:
var data = Unity3dViewer.data();
data.gameInstance.SendMessage("BrowserCommunication", "GetAllLightsJson");
Meanwhile the script on the unity side of things looks like this:
public void GetAllLightsJson()
var lights = GameObject.FindObjectsOfType<LightController>();
string json = "[";
foreach (var light in lights) {
Vector3 loc = light.transform.position;
json = json + "{ 'location' : {'x': " + loc.x * 0.3048 + ",'z': " + loc.y * 0.3048 + ",'y': " + loc.z * 0.3048 + "}," + "'normal' : {'x':0,'y':0,'z':-1} },";
}
json = json.Remove(json.Length - 1);
json = json + "]";
}
Now for some reasons this causes the error:
An error occurred running the Unity content on this page. See your browser JavaScript console for more info. The error was:
TypeError: self.performance is undefined
where the console shows the following details:
exception thrown: TypeError: self.performance is undefined,_emscripten_get_now@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4:2:350525
@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4 line 2 > WebAssembly.instantiate:wasm-function[7069]:0x382dd2
@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4 line 2 > WebAssembly.instantiate:wasm-function[7068]:0x382b8b
@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4 line 2 > WebAssembly.instantiate:wasm-function[9262]:0x471c95
@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4 line 2 > WebAssembly.instantiate:wasm-function[8647]:0x429614
@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4 line 2 > WebAssembly.instantiate:wasm-function[8647]:0x42962b
@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4 line 2 > WebAssembly.instantiate:wasm-function[8642]:0x428840
@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4 line 2 > WebAssembly.instantiate:wasm-function[8636]:0x42707e
@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4 line 2 > WebAssembly.instantiate:wasm-function[99461]:0x29daf84
UnityLoader.db99c972aa57aeb012a876572a3f4cf4/Module.dynCall_v@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4:2:519017
browserIterationFunc@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4:2:131846
runIter@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4:2:134938
Browser_mainLoop_runner@blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4:2:133383
UnityLoader.js:4:10740
printErr
http://localhost:50922/dist/Viewer/Build/UnityLoader.js:4:10740
runIter
blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4:2:135029
Browser_mainLoop_runner
blob:http://localhost:50922/62fd591f-d987-4bcf-aff1-9ae5cb3530d4:2:133383
And crashes unity in it's entirety (the webplayer becomes unresponsive). Anybody know what this errors means and how to fix it?
Upvotes: 0
Views: 838
Reputation: 124
Although, it would appear that you are trying to access something either outside of scope or that isn't being initialized properly. Hence
self.performance is undefined
Try tracing where your call goes, exactly. Additionally below is an excerpt from Unity3D's site:
Code visibility
Starting from Unity 5.6 all the build code is executed in its own scope. This approach makes it possible to embed your game on an arbitrary page without causing conflicts with the embedding page code, as well as makes it possible to embed more than one build on the same page.
If you have all your JavaScript code in the form of .jslib plugins inside your project, then this JavaScript code will run inside the same scope as the compiled build and your code should work pretty much the same way as in previous versions of Unity (for example, the following objects and functions should be directly visible from the JavaScript plugin code: Module, SendMessage, HEAP8, ccall etc.).
However, if you are planning to call the internal JavaScript functions from the global scope of the embedding page, you should always assume that there are multiple builds embedded on the page, so you should explicitly specify which build you are referencing to. For example, if your game has been instantiated as:
var gameInstance = UnityLoader.instantiate("gameContainer", "Build/build.json", {onProgress: UnityProgress});
Then you can send a message to the build using gameInstance.SendMessage(), or access the build Module object using gameInstance.Module.
The only way to further understand is to see the whole script in whole. Additionally, whether the script that is making the call is embedded in your project or not. Hopefully this helps.
Upvotes: 1