1

Okay so I have this bug that I really don't get the logic off. It's either something ultra stupid, or something stack related I don't yet understand...

Here is my code:

public void LevelLoad(Level lev)
{
    #if UNITY_ANDROID && !UNITY_EDITOR
    AudioManager.Instance.ReleasePool();
    #endif

    currentlyDisappearedFigures = 0;

    if (!lev.Equals(currentLevel))
    {
        currentLevel = lev;
        currentLevel.transparentQTY = 0; currentLevel.normalQTY = 0; currentLevel.totalQTY = 0;
        currentLevel.hasDeath = false; currentLevel.hasND = false; currentLevel.hasNormal = false; currentLevel.hasTransparent = false;
        foreach (Figure fig in currentLevel.Figures)
        {
            if (fig._figureType != null)
            {
                if (fig._gameObject.CompareTag("Hard"))
                    fig._figureType.ResetHard();
                fig._figureType.RefreshFigure(currentLevel);
                currentLevel.totalQTY++;
            }

        }
    #if UNITY_ANDROID && !UNITY_EDITOR
        if (lev.totalQTY > 22)
            lev.totalQTY = 22;
        AudioManager.Instance.CreatePool(currentLevel.totalQTY);
        Debug.Log("currentLevel.totalQTY-"+currentLevel.totalQTY);

        AudioManager.Instance.LoadAudio(currentLevel.hasNormal, currentLevel.normalQTY,
            currentLevel.hasTransparent, currentLevel.transparentQTY,
            currentLevel.hasND, currentLevel.hasDeath);
        Debug.Log("HasNormal-" + currentLevel.hasNormal + ",normalQTY-" + currentLevel.normalQTY + ",hasTransparent-" +
            currentLevel.hasTransparent + ",transparentlQTY-" + currentLevel.transparentQTY + ",hasND-" +
            currentLevel.hasND + ",hasDeath-" + currentLevel.hasDeath);
    #endif

See the:

Debug.Log("HasNormal-" + currentLevel.hasNormal + ",normalQTY-" + currentLevel.normalQTY + ",hasTransparent-" +
            currentLevel.hasTransparent + ",transparentlQTY-" + currentLevel.transparentQTY + ",hasND-" +
            currentLevel.hasND + ",hasDeath-" + currentLevel.hasDeath);

All of those print either FALSE, or ZERO, and I don't know why.

The thing is, I am instantiating them in:

fig._figureType.RefreshFigure(currentLevel);

Here is the inside of FigureType.RefreshFigure(). It's irrelevant, but the Debug.Log inside it shows different from the one I mentioned above:

public void RefreshFigure(Level lev)
{
    gameObject.SetActive(true);     

    _collider.enabled = true;
    if(_type != FigType.Death && _type != FigType.Transparent)
        _collider.isTrigger = false;
    ResetTransform();



    if (_type == FigType.Normal)
    {
        lev.hasNormal = true;
        lev.normalQTY++;
        Debug.Log("Current Level has Normal: " + lev.hasNormal);
        Debug.Log("Current Level Normal QTY issssss: " + lev.normalQTY);
    }

Those 2 Debug.logs, inside RefreshFigure() show True, and 1.

I don't get where and why the Bool becomes false, and the Integer becomes zero?

Fredrik Widerberg
  • 3,068
  • 10
  • 30
  • 42
Kokolo
  • 250
  • 2
  • 12
  • 2
    I notice you are using "Instance" which won't work in Unity. It's actually **incredibly easy** to have systems like mangers in Unity - some new hobbyist users of Unity don't realize this: http://stackoverflow.com/a/35891919/294884 Fortunately it just could not be easier, enjoy – Fattie Nov 30 '16 at 12:19
  • Wow. Basically all I should do is put the AudioManager in the _preload scene, and add Don'tDestroyOnLoad script on the same object the AudioManager is? – Kokolo Nov 30 '16 at 12:41
  • in fact @JoeBlow , all my managers (Game, Menu, etc...) use the concept of PersistentSingleton with .Instance and stuff. Should I do the same for all of them? – Kokolo Nov 30 '16 at 12:52
  • 1
    **"Wow. Basically all I should do is put the AudioManager in the _preload scene?"** - yes, that is 10000% correct. moreover, you actually ***have to*** do that. (I can't be bothered explaining why, because it's been written about 100s of times!) – Fattie Nov 30 '16 at 12:57
  • 1
    What happened is, in the early days of Unity, someone from another background accidentally wrote some example code that does it the wrong way, not realizing Unity is a game engine. That one bad example ***propagated 100s of times on the internet, getting more wrong each time***. Just to reassure you, **the actual way you do it, is utterly simple, tremendously simpler!** It's all good news. – Fattie Nov 30 '16 at 12:59
  • 1
    "all my managers (Game, Menu, etc...) use the concept of..." Yes, unfortunately that is *completely wrong* - heh. Sorry for the bad news. (1) you will have to change all your projects. (2) again, fortunately, the actual way you do it is just ridiculously easy, a child can do it. "Unity is easy". – Fattie Nov 30 '16 at 13:00
  • @JoeBlow Gorgeous, utterly gorgeous. Thanks sir, wish you lots of happy days :) – Kokolo Nov 30 '16 at 13:05
  • I just hope your project works out, cheers! – Fattie Nov 30 '16 at 13:16
  • @JoeBlow One more thing on the go: does unity automatically load next scene, if **preload** scene is at index 0? Because I felt like it does, from your comments on other posts, **but it doesn't.** – Kokolo Nov 30 '16 at 13:27
  • **you are totally 100% correct**. I always have a simple script called something like "actually launch the app.cs" ! The only purpose of the script is to "kick off" the app by going to (say) your "simulated splash screen", network loading scene, main screen or whatever. – Fattie Nov 30 '16 at 13:30
  • @JoeBlow I can't be more grateful for simplifying the whole **Singleton** process... ...however, the original problem remained, and again the **boolean is true**, and the **integer equals 1** inside RefreshFigure(), yet, they _remain as false and 0 in LevelLoad()_. – Kokolo Nov 30 '16 at 13:41
  • 1
    re the original problem - I'll try to have a look at it. U could probably make big progress by adding more "Debug.Log" .. statements, inside RefreshFigure etc etc. it may be un-debuggable since such instantiations, pools etc are non-determinate in Unity, you know. – Fattie Nov 30 '16 at 13:51

0 Answers0