Lives System messed up in WebGLBuilld

I think there is a problem with the scriptable object in the build. Correct me if i’m wrong

done all what you said Nina and it’s not changed a thing. i have found that sometimes i need to display the Scriptable Object in the inspector In order for the lives to add 1 extra life every level in the editor. Seems like this could be the problem.

found this not sure if this relates to problem i’m getting though http://answers.unity.com/answers/874634/view.html

Hi again! Good news! I was able to replicate the issue and fixed it!

First of all, change your GameplayController script to this, you’ll get an error, this is just for clarity, that script was doing instances and other things that weren’t required, that could also be part of the solution, not 100% sure, but it never hurts to keep your code as clean as possible.

using UnityEngine;
using TMPro;

public class GameplayController : MonoBehaviour
{
    [SerializeField] private TextMeshProUGUI lifecount;
    [SerializeField] Lives lives;

    void Start()
    {
        CountLives();
    }

    public void CountLives()
    {
        lifecount.text = "Lives: " + lives.numLives;
    }
}

To fix the error after those changes, this is in your LoseColider script:

    private void OnTriggerEnter2D(Collider2D collision)
    {    
        lives.numLives--; 
        if (lives.numLives <=0)
        {
            SceneManager.LoadScene("Game Over");  
        }
        else
        {
            FindObjectOfType<GameplayController>().CountLives(); //Change the error to this
            Ball.ballInstance.SetBallPosition();
        }
        AudioSource.PlayClipAtPoint(ballLostSound, transform.position, 1f);
    }

And now to fix the error, let me explain what happened. There are two common issues as to why things might work in the editor but not in the final build, as Nina explained, the library might be an issue, if that doesn’t solve anything then it’s because there’s some racing going on. Racing is when two things are running at the “same time” but they shouldn’t run at the “same time”, but instead they should run in a specific order.
In this case, the code tried to add a new life but also update the text at the same time, so sometimes it work, sometimes it didn’t. To fix you’ll have to change the order in which those scripts are executed. To do this just change the Start method to an Awake method in your LoseColider script.

    private void Awake() //Instead of Start use Awake
    {
        if (SceneManager.GetActiveScene().name == "Level 1")
        {
            lives.numLives = 3;
        }
        else
        {
            lives.numLives += 1;
        }
    }

That’s it, that should solve your issues.

I also have some bad news, I found some other issues with the Pause menu and the ball. When I open the Pause Menu and go to the Main menu from there, the game will still be paused, we don’t want that, that’s an easy fix, I’ll leave that to you.

There’s also an issue with the ball, it might end up in an infinite loop, I was able to solve that by setting the ball’s gravity scale to 0.5 instead of 1.

If you are still having issues I’ll send you the version I have as a package, you’ll just have to order the levels in the builds settings.

Awe thankyou ! bless :smiley:

Did @Yee’s solution fix the issue for you?


See also:

just going to do it now was bit busy with family before


I’m not having that issue, so you probably erased something you shouldn’t have.

That error has something to do with your “Ball” script, check the “SetBallPosition” method, check if it isn’t missing something.

Question, not trying to be mean or anything, but I need you to be truly honest to be actually helpful, Do you understand how your code works? I’m asking this because I’m seeing you posting every single error, that error in particular has nothing to do with the fix I gave you, so you should be able to solve it on your own with the knowledge the course has given you so far. If you don’t truly understand what is going on, then it’s actually a pretty good thing, we learn a lot from messing things up, but I also would suggest you forget about this project and move on with the course, but this time, forget about implementing menus and all that stuff, just follow the course, do the challenges, learn from that, then come back to this project after you gain a little more knowledge, also you’ll have a lot more fun, but you gotta be super honest, if you are not truly grasping the basics you should totally re-start the course.

All the help I’ve given you is more of a guide rather than a copy-paste thing, if you don’t know what is going on you should stop and ask before doing anything else, otherwise you’ll just end with a lot of code that you don’t understand causing you lots of issues.

I find coding difficult to understand yes. Perhaps im not not cut out for this

some of the challenges i find impossible must be the way my brain is wired

i have not found the course easy

I’ve played your game, and to be honest it’s really cool and fun, the art is great, so you are totally cut for this, but coding is hard if you don’t get the basics, just give the course another go, I bet you’ll have a much easier time finishing this game after you do that, also, there’s a lot of people more than willing to help you here, if you have any question, ask, don’t be afraid, if you don’t get what a variable is or what certain things are doing, just ask.

If you are having issues with some challenges that’s perfectly normal, just keep trying and keep asking! I suggest you re-start the course, but this time ask every single thing you don’t get, you’ll see how easier it will get, also, keep messing things up, that’s how we learn.

i enjoy the concept art music side of it coding stresses me out

ive gone over it more than 3 times the coding is not sinking in to my brain

I truly enjoy coding because I see it as a game or a puzzle, maybe you just need to shift your view a little bit, your brain might be wired a certain way, but you can change those wires, just keep trying, don’t give up.

its the way my brain is wired i think

i dont enjoy coding when it stops me from finishing project so therefore i do not like coding atm

i rather do the art and music tbh

What’s your goal? What do you want to achieve with this course?

Privacy & Terms