Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Unity 5 WebGL data binding?

Discussion in 'Unity 5 Pre-order Beta' started by Zaibach333, Oct 26, 2014.

  1. Zaibach333

    Zaibach333

    Joined:
    Sep 4, 2011
    Posts:
    19
    Since WebGL is javascript, if you had other elements in the page relying on values from unity, is there any support going towards bound access to those variables? This could be really useful for integrating WebGL canvases throughout existing web applications.
     
  2. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    For sure there is a way to communicate back and fourth with Javascript.

    My best bet is that it is the same as with the WebPlayer:
    Code (csharp):
    1. Application.ExternalCall("MyJavascriptFunction", myData);
     
  3. Zaibach333

    Zaibach333

    Joined:
    Sep 4, 2011
    Posts:
    19
    true, but how would I go about say

    Code (CSharp):
    1. void Update() {
    2.      MyBoundData.position += Vector3.up * 4.0f * Time.deltaTime;
    3. }

    and simply do this in javascript

    Code (JavaScript):
    1. $("MyParagraphID").val(MyUnityObject.MyBoundData.position.x);
    and do this without a ton of sync calls in high level code.

    It just seems like a very possible thing when there's no barrier of a webPlayer
     
  4. RalphH

    RalphH

    Unity Technologies

    Joined:
    Dec 22, 2011
    Posts:
    592
    "It just seems like a very possible thing when there's no barrier of a webPlayer"

    This is somewhat of a misassumption about how we convert the C# types; they are all represented by data in a singular typed array, which is shared by both the converted managed code and the engine code, through a few conversion steps; explicit marshalling from C# types to JavaScript types will always need to happen.
     
  5. Zaibach333

    Zaibach333

    Joined:
    Sep 4, 2011
    Posts:
    19
    Thanks for jumping in, you see the benefit of binding at least, unfortunate that it isn't an option. If I wind up in a situation which could use it in unity 5... I'd just have to keep doing it like the web player. Again, thanks for the clarification.