Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity3D web player is disappears when Facebook chat window is active

Discussion in 'Editor & General Support' started by claytoncurmi, Mar 26, 2014.

  1. claytoncurmi

    claytoncurmi

    Joined:
    Jul 6, 2010
    Posts:
    168
  2. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    1,067
    Ha! Kringlan! Haven't been there in a while :)

    I suspect that is a FB issue and how they handle the chat window. Might be a shot in the dark but have you tried enabling "Run in background" in the player settings? This might have some downsides on your game should people expect it to not run in the background.
     
  3. claytoncurmi

    claytoncurmi

    Joined:
    Jul 6, 2010
    Posts:
    168
    Thanks for replying.

    Haven't tried that yet... but I don't want the game to keep on running whilst it is in the background. I will make a build and see what happens, just in case.

    Regards,
    Clayton
     
  4. Torguise100

    Torguise100

    Joined:
    Feb 6, 2013
    Posts:
    2
    I too have encountered the same issue and have noticed it to happen with any of the drop menus on FaceBook
    I have "Run In Background" enabled however the issue still occurs
    I would be very grateful for any advice or pointers on how I may fix or if not work around the issue, if there is any way around it

    Thanks
     
  5. taxvi

    taxvi

    Joined:
    Feb 18, 2013
    Posts:
    30
    claytoncurmi

    i see you have fixed your problem could you share your solution? I'm struggling with this one too

    thanks!
     
  6. taxvi

    taxvi

    Joined:
    Feb 18, 2013
    Posts:
    30
    Solved it. I know web player is about to die and probably no one is going to see this but still, if you are having the same problem here you go:

    The core of the problem was that opening the facebook chat was changing the style of my html elements, I have no clue why. So what I did was add a listener to the html style changes via javascript plugin. Huge thanks to this guy: http://stackoverflow.com/a/20683311/3183423

    What Was Happening:
    I'm using google developer tools. What I found is that opening the chat was changing unity's inline css here inside the facebook canvas, it was setting the width and height to -10000px (the image is already from the fixed version):



    How To Solve It:
    After following the upper mentioned stackoverflow answer I created an observer to hard reset the css if it's ever changed. This is the code I added in my javascript plugin:

    Code (JavaScript):
    1. function FixFBWebPlayerAnomaly(){
    2.     var observer = new MutationObserver(function(mutations) {
    3.         mutations.forEach(function(mutationRecord) {
    4.             var _webPlayer = document.getElementById('unityPlayer').firstChild;
    5.  
    6.             if(_webPlayer.style.cssText != "display: block; width: 435px; height: 700px;"){
    7.                 _webPlayer.style.cssText = "display: block; width: 435px; height: 700px;";
    8.             }
    9.         });
    10.     });
    11.  
    12.     var target = document.getElementById('unityPlayer').firstChild;
    13.     observer.observe(target, { attributes : true, attributeFilter : ['style'] });
    14. }
    call this method from your game at the very start with Application.ExternalCall(). If you call it from the plugin side it may be too early, the webplayer element may not be created yet.

    Hope this helps someone before the webplayer is finally sent to the void.
     
    Last edited: Aug 7, 2015