Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by unity_eUpT1lvqDGObtw · Nov 13, 2019 at 10:32 AM · buildwebgldebug

Code doesn't work in WebGL build

Hi,

I have a script that perfectly works in the Unity Editor, however once I build it in WebGL, it does not work. What also is worth mentioning, is that my Debug.Log statements from this script are not being printed in the console.

The script is moving the object by a specific distance in "jump movements" until it reaches a breakpoint and then moves it back to the centre. Once the game object is back, the break point should increase and therefore the game object should go further out. However, in WebGL it jumps out once and then goes back and does not increase the breakpoint. I have a similar movement, that is fluent, instead of jumping and that works fine both in the editor and the build.

Here's my code:

 protected void CheckForChangeDirection(bool condition){
         if(condition){
             goingBack = false;
             direction = -direction;
         }
         else if(Mathf.Abs(transform.position.x) >= Mathf.Abs(currentBreakpoint) && !goingBack){
             goingBack = true;
             direction = -direction;
             NewBreakPoint();
         }
     }
 protected void NewBreakPoint(){
         currentBreakpoint += increaseDistance;
         posneg += new Vector2(increaseDistance, 0);
     }
 
     private IEnumerator Jump(){
         yield return new WaitForSeconds(0.75f);
         Move();
         CheckForChangeDirection(transform.position.x * posneg.x * 10 <= 1);
         StartCoroutine("Jump");
     }
     protected override void Move(){
         transform.position = (Vector2)transform.position + speed*direction;
     }


Please, please help, I have no idea why this is happening. And have no idea how to debug it, as it works in the editor and doesn't print the Debug.Log statements in the browsers console...

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Nov 13, 2019 at 12:12 PM

I can't see anything obvious. However if the problem is really part of those snippets it's most likely your StartCoroutine call with a string argument. There really is no reason to use that, at all.


We don't see where you initially start the coroutine, but you really should use

 StartCoroutine(Jump());


Constantly restarting the coroutine every 0.75 seconds is a bad idea. You will generate tons of garbage that way. Just keep the coroutine running:

 private IEnumerator Jump()
 {
     while(true)
     {
         yield return new WaitForSeconds(0.75f);
         Move();
         CheckForChangeDirection(transform.position.x * posneg.x * 10 <= 1);
     }
 }

This will have the same effect but does not constantly terminate and restart the coroutine.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image unity_eUpT1lvqDGObtw · Nov 13, 2019 at 12:47 PM 0
Share

Thank you for the answer! I will see if it helps.

avatar image unity_eUpT1lvqDGObtw · Nov 13, 2019 at 01:25 PM 0
Share

Now I'm getting the Debug.Log output in the console, so I can debug it, thank you!

avatar image
0

Answer by unity_eUpT1lvqDGObtw · Nov 14, 2019 at 10:43 AM

It turned out that the problem was with the condition: transform.position.x posneg.x 10 <= 1. The value was swapping between 0 and 1 and in the editor 1 <= 1 was returning false, while in the browser it was correctly true. Fixed by changing to transform.position.x posneg.x 10 < 1.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

132 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

How to use Webgl Debug Symbols? 0 Answers

WebGL cross-domain error when loading .mem file from remote 1 Answer

WebGl build keeps failing 0 Answers

Lighting doesn't work properly in WebGL build 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges