Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to Integrate Unity and Blockly?

Discussion in 'Editor & General Support' started by alexandrol, Jan 29, 2016.

  1. alexandrol

    alexandrol

    Joined:
    Jan 29, 2016
    Posts:
    1
    I would like to know if there are integration experiences of Unity games controlled through Blockly.
    Specifically I would like to evaluate the possibility of developing educational games with Unity and controled by Blockly as those offered in https://studio.code.org/

    Thanks in advance
     
    czbming, zdlmaxwell and DohaRobo like this.
  2. Shizola

    Shizola

    Joined:
    Jun 29, 2014
    Posts:
    470
    One year later, has anybody tried this?
     
  3. UnnikrishnanR

    UnnikrishnanR

    Joined:
    May 14, 2013
    Posts:
    3
    I had integrated Blockly into a WebGL project I was working on earlier this year. I have since then moved on to creating a blockly/scratch like environment inside Unity (using UI.Canvas elements) as I needed portability across platforms (Blockly does have Android support but I think the process integrating the BlocklyActivity into a Unity based app would not be trivial).

    The key is to understand that Unity WebGL runs on asm.js [0] which is practically machine level byte code for the browser JS engine, which means you will not be able to directly access game objects, scripts and other features in Unity from the webpage. The solution I figured out was to first integrate Blockly[1] into a WebGLTemplate [2] and then use Application.ExternalCall [3] (Unity has since deprecated this and recommends creating a jslib) to call the eval function [4] in Blockly (after converting your blockly workspace to JS/Python/... code first) [4]. Though you cannot access Unity elements directly, you can still communicate from your blockly code to Unity using the SendMessage function [5]. I was not very happy with this roundabout way plus I did not like the design choices the Blockly team made (like the way they restrict the hues one can use for coloring custom blocks). Do let me know if anyone figures out an easier way to integrate Blockly into Unity and especially one that is portable across all platforms!

    [0] https://blogs.unity3d.com/2014/04/29/on-the-future-of-web-publishing-in-unity/
    [1] https://developers.google.com/blockly/guides/configure/web/fixed-size
    [2] https://docs.unity3d.com/Manual/webgl-templates.html
    [3] https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html
    [4] https://developers.google.com/blockly/guides/app-integration/running-javascript
    [5] http://answers.unity3d.com/questions/825602/browser-to-unity-webgl-communication.html
     
    RohitExtramarks and Shizola like this.
  4. YumaS-

    YumaS-

    Joined:
    Nov 16, 2017
    Posts:
    1

    I also want to integrate Unity and Blockly but I can't understand how to integrate Blockly into a WebGLTemplate. Would you tell me more details to integrate Blockly into a WebGLTemplate?
     
  5. Silence_ZM

    Silence_ZM

    Joined:
    Jul 2, 2017
    Posts:
    1
    [QUOTE =“YumaS-,post:3347099,member:1578065”]我也想整合Unity和Blockly,但我无法理解如何将Blockly集成到WebGLTemplate中。您能否告诉我将Blockly集成到WebGLTemplate中的更多细节?[/ QUOTE]
    ñ也请告诉我怎么办?
     
  6. garasouleima01

    garasouleima01

    Joined:
    Dec 9, 2018
    Posts:
    3
    i have the same problem any helps
     
  7. suryakumara33

    suryakumara33

    Joined:
    Nov 28, 2019
    Posts:
    3
    Hi.. I have done your step.. now I still get a problem.. I cannt combine 2 block.. it running at the same time not one by one
     
  8. htq110219891

    htq110219891

    Joined:
    Sep 21, 2018
    Posts:
    3
    We have studied and practiced for 4 years, combining unity and blockly. And completed version 1.0. We used it to create complex games and successfully released them. Compared with the code, it reduces the development time by 70%.
    Version 2.0 is currently under development and has been developed to the end. It will be announced after completion and free to use.
     
    mgear and Shizola like this.
  9. MKrohn

    MKrohn

    Joined:
    Apr 5, 2018
    Posts:
    23
    Hi htq110219891,

    that sounds great, though I wonder what exactly "version 1.0" and "version 2.0" relate to. Are you part of the Blockly developers and talk about a new version of Blockly? Or are you a Unity developer who wrote a framework for Blockly?
     
  10. htq110219891

    htq110219891

    Joined:
    Sep 21, 2018
    Posts:
    3
    The problem with version 1.0 is that it runs slowly, and the official Bolt also has this problem. Version 2.0 We rewrite the underlying code and support incremental updates of the code. The running speed can surpass the code, and the actual test is 18 times faster than Bolt.

    We are not google staff, but we have provided code for blockly. We have used blockly to develop many tools and are very familiar with Unity, so we thought of combining the two. The results are great.