- Home /
unity webGL show only one camera when use multiple cameras
I think this should be a common problem but I cannot find any answer in the internet.
I use two camera, one as minimap camera and the other as main camera. just like below image

everything is fine when I build a normal exe. However, when I make a webGL file, only one camera would show in the game.

and the viewport rect setting do not work now. What should I do to show all cameras views?
Answer by HeavensSword · Jun 06, 2019 at 08:50 PM
Did you ever find a resolution to this?
I have a webGL project in which i'd like to use splitscreen/multi-cameras.
Answer by jmoois · Oct 08, 2019 at 07:44 PM
@Hong-En-Tsai and @HeavensSword,
When exporting to WebGL, Unity doesn't export Camera.clearflags settings that allow you to merge camera outputs together. Unity defaults to Skybox (or maybe solid color), but you lose the settings "Depth" or "Nothing" if you had your cameras set that way.
All is not lost however! You can add a tiny piece of javascript into the output of the webgl build to make it keep clearflags. It's mentioned here - https://docs.unity3d.com/Manual/webgl-graphics.html but I'll write it out here (perhaps going into more detail then is necessary in case anyone reading this doesn't know Javascript.)
Go in to the index.html page that was placed in the root of whatever directory you published your webgl build to. Open up the index.html in an editor. If you used the Minimal WebGLTemplate when you published from Unity find the line that says:
UnityLoader.instantiate("unityContainer", "%UNITY_WEBGL_BUILD_URL%");
and change it to
UnityLoader.instantiate("unityContainer", "%UNITY_WEBGL_BUILD_URL%", {
Module: {
"webglContextAttributes": {"preserveDrawingBuffer": true},
}
});
If you used the Default template instead, the line to look for will be like the following:
var unityInstance = UnityLoader.instantiate("unityContainer", "%UNITY_WEBGL_BUILD_URL%", {onProgress: UnityProgress});
change it to:
UnityLoader.instantiate("unityContainer", "%UNITY_WEBGL_BUILD_URL%", {
onProgress: UnityProgress,
Module: {
"webglContextAttributes": {"preserveDrawingBuffer": true},
}
});
Note that every time you republish your WebGL build from Unity, it will overwrite the index.html and you'll have to re-add it. So you might want to create a Custom WebGL Template (https://docs.unity3d.com/Manual/webgl-templates.html) that you can set your Unity publish settings to and make the changes to the version of index.html in there).
Answer by justaddice83 · Nov 30, 2020 at 09:38 AM
This appears to be no longer an issue, unless however, you change the viewport size for one of the cameras, in which case you loose the back camera rendering. But this then appears to be a different issue which I will submit.
Your answer
Follow this Question
Related Questions
WebGl does nothing 2 Answers
How to upload WebGL games on reputed websites? 1 Answer
Webgl facebook integration 0 Answers
WebGL -Chrome seems to do nothing while loading WebGL appllication 0 Answers
webgl rotate texture on the face of cube using glmatrix 0 Answers