Strange behavior in Awake ?

Hello!
I have a doubt that I am doing something wrong here!

I have a List in one script and in another I am accessing to it like this:

private void Awake()
    {
        totaleDomande = DatabaseManager.DM.Domanda.Count;
        Debug.Log("Totale Domande Disponibili: " + totaleDomande);
    }

if that list “Domanda” counts 4 … I have four “debug” statements. (I mean four times saying "Totale Domande Disponibili: 4).

if that list “Domanda” counts 8 … I will have that debug eight times.

is that correct or I am messing somewhere?

Thanks!!!

Hi!

From this script alone, assuming it only exists once;

If you have 4 in the list you will get 1 x “Totale Domande Disponibili: 4”

if you have 8 in the list, you will get 1 x “Totale Domande Disponibili: 8”

This assumes that the list is already populated though. You might want to initialize and populate your list in Awake(), and then use the Count property in Start(). This ensures the list exists and is full before your Debug.Log happens because Start() runs after Awake().

you are duplicating your scripts, it means you have 8 gameobjects that are running the awake 8 times

1 Like

So… That’s weird!
In the first script the list is populating from a SQL database in a IEnumerator… maybe it’s this but I think It’s weird anyway!

Thanks for your reply!!! I found the problem! You are right … another script is calling “x times” Scenemanager.LoadScene

Now I have to work on that!