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

WebGl and Eval()

Discussion in 'WebGL' started by ornicar, Nov 4, 2015.

  1. ornicar

    ornicar

    Joined:
    Mar 17, 2015
    Posts:
    6
    Hi,

    I am working on a Unity project developed in JS for the Unity WebPlayer, and that uses eval(), and I need to build it now for WebGl.

    Eval() is not supported for the WebGl build. Is there any chance it's going to ? Is their any easy way to work around the problem ?

    I have seen posts about JSON.parse() or window.eval() but I have no idea what they are about.
     
  2. pchuri

    pchuri

    Joined:
    Aug 18, 2014
    Posts:
    12
    Webgl Build can use 'Application.Eval'.
     
  3. ornicar

    ornicar

    Joined:
    Mar 17, 2015
    Posts:
    6
    It seems that Eval is not a member of Application.

    Maybe you meant Application.ExternalEval, but that doesn't work for me because the code is then excuted within the context of the wrapper html page. It needs to be evaluated within my object class, as the simple eval() did.

    Did I miss something ?
     
  4. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    I am not completely sure what's your use-case, however, you may want to take a look at this page which explains your options when it comes to interact with Javascript.
     
  5. tamariworld

    tamariworld

    Joined:
    Nov 3, 2013
    Posts:
    1
    Hi, is there any option to use a function like eval() for WebGL?
    In my project i use code like this: (is working for Unity WebPlayer... but not for WebGL-Build)

    function MyFunction(param : String){
    ....
    js_command = js_command +";";
    js_command = Regex.Replace(js_command, "(window.alert)+", "create");
    eval(js_command);
    ...
    }

    I´am reading external-JS-Code and then eval() this within the unity-project. Is there an alternative for WebGL?
     
  6. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    As was already written in this thread, Application.ExternalEval should do what you want.