Lives System messed up in WebGLBuilld

Lives System isn’t working correctly in Local WebGL build as it does in Game Editor. Im getting these errors from google


and sometimes i get this

but when i press play they go

Hi Louise,

Do you have any script blockers or any extensions installed in Chrome? I’m not sure if these warnings refer to issues in your project.

The error messages in your Unity console do. It seems that there might be an internal problem in Unity because the error messages are not referring to any of your classes. Go to Window > Layout and select the “Default” layout.

Then test your game carefully and remember the last thing you did. If an error message appears, you know where you could look for the issue.

If the LivesSystem does not work but if there are not any error messages, add Debug.Logs to your LivesSystem code; ideally, with meaningful messages. In File > Build Settings, enable the “development build”. Build your game, test it in your browser. If the LivesSystem still does not work, check your console again. Your Debug.Log messages should appear. If they do not appear at all, something probably happened to the LivesSystem object.

I just got loads of the same red error messages again as above. pressed play in games console and got this

Which version of Unity do you use? I’m still wondering if these errors are caused by an internal problem in Unity.

Try double click on the error message. To which line in your code does it refer (given something happens when you double click on the message)?

I’m using Unity 2020.15f1

says label text font taking too long at begging of build only can do 50 percent

When i play 1st level in local browser. I complete first level without loosing any lives then goes to Game Over

tried another build played in browser. this time i completed level loosing no lives but in display it read (Lives: 2) in which your supposed to gain a life (Lives: 4). Then when continued i lost a life but still stuck at Lives 2 then lost another life and then went down to Lives 1. :confused:

Do you mind if I ask to see the code for your lives system?

Sounds like an issue in the code.

Did you implement Rick’s “singleton”? If so, check if your “singleton” calls gameObject.SetActive(false); in the same if-block where Destroy(gameObject); gets called. If there isn’t that line of code, add it.

If adding the line does not fix the issue, you will have to add Debug.Logs with meaningful messages to your LivesSystem code. What the text display says in the game is irrelevant for now. First, make sure that your LivesSystem works as expected. If it does, you could look for the issue which prevents the correct values from getting displayed.

2 Likes

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

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

private void Awake()
{
    MakeInstance();
}

// Start is called before the first frame update
void Start()
{
    CountLives(LoseColider.numLives);

}

// Update is called once per frame
void MakeInstance()
{
    if (instance == null)
    {
        instance = this;
        print("making instance");
    }
}
public void CountLives(int numLives)
{
    Debug.Log("Number of lives is" + numLives);
    lifecount.text = "Lives: " + numLives;
}

}

‘’’
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LoseColider : MonoBehaviour {

public static int numLives;


private SceneManager sceneManager;

[SerializeField]
private AudioClip ballLostSound;
[SerializeField] Lives lives;

private void Start()
{
    if (SceneManager.GetActiveScene().name == "Level 1")
    {
        numLives = 3;

    }
    else
    {
        numLives += 1;
    }

}


 private void OnTriggerEnter2D(Collider2D collision) {
    
    numLives--; 
    if (numLives <=0)
    {
        SceneManager.LoadScene("Game Over");
        
        
    }
    else
    {
         GameplayController.instance.CountLives(numLives);
        Ball.instance.SetBallPosition();
    }
    AudioSource.PlayClipAtPoint(ballLostSound, transform.position, 1f);
}

}
‘’’

‘’'using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = “Lives”)]
public class Lives : ScriptableObject
{
public int numLives;

}
‘’’

It all works fine until making a WebGL build

Actually the lives system isn’t working correctly in standalone either only in the editor game window

Probably end up having to re do it all again 3d time lucky :weary: to be fare i have added a lot to it. It will be worth the effort in the end i’m sure. Probably bugged it out while messing around with coding

I think I found the issue. It’s not the lives system.

In your Ball script you have a public static variable called “instance” and in your GameplayController script you have another public static variable called “instance”, you can’t have two static variables with the same name, you gotta change one of those, preferably both.

ive noticed that the ball is at bit jittery in WebGL build local from when being played in the game editor.

so i just have to change one of the names from “instance” to what ?

To anything you like, but that might not be the issue after all. I build the game with the version I have and had no issue. So not sure what is going on.

Privacy & Terms