#m_CanvasGroupCache is null inside Selectable.cs

1 messages · Page 1 of 1 (latest)

mellow flicker
#

Hi, I have a problem related to canvas groups:

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.UI.Selectable.ParentGroupAllowsInteraction () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Selectable.cs:445)
UnityEngine.UI.Selectable.OnEnable () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Selectable.cs:521)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
bool ParentGroupAllowsInteraction()
        {
            Transform t = transform;
            while (t != null)
            {
                t.GetComponents(m_CanvasGroupCache); //<- "m_CanvasGroupCache" is null...
                for (var i = 0; i < m_CanvasGroupCache.Count; i++) // throws here
                {
                    if (m_CanvasGroupCache[i].enabled && !m_CanvasGroupCache[i].interactable)
                        return false;

                    if (m_CanvasGroupCache[i].ignoreParentGroups)
                        return true;
                }

                t = t.parent;
            }

            return true;
        }

It is Called OnEnable(), also in the editor outside of play mode, and while playing and the parenting canvas group has changed. I am overriding the Selectable class, but this is the only instance where it causes a problem, and it still works fine I just get this error for some reason. is anyone has any idea why this happens and how do i get this fixed? or where to check?

I cant see anything suspicious in my part of the code.
I restarted unity.
I rebooted my pc...

lucid skiff
#

weird, it should be initialized when the Selectable is instantiated...

#

if you go to the declaration of m_CanvasGroupCache, do you see the initialization?

mellow flicker
#

yes, its initialized

#

this is unity code... that why im so clueless

lucid skiff
#

what if you reset the library?

mellow flicker
#

how do i do that?

lucid skiff
#

close the project, delete the Library folder, reopen the project

#

it'll take a bit longer to reopen the project since it'll have to rebuild the library

mellow flicker
#

That sounds good

#

im going to try that...

#

I still have the same problem..

#

so problem solved...

#

The problem was that rider created a constructor for this class automatically after I created getters for my private fields...

#

It never happened before...

lucid skiff
#

...for the internal class?

mellow flicker
#

no, for my override

#

and it just created my class after it called on enable, the child class was already constructed with "my new constructor" and m_CanvasGroupCache was null ...

#

I truly hate this AI features...

lucid skiff
#

what do you mean your override? thonk

mellow flicker
#

public class PerkSelectButton : Selectable
{

lucid skiff
#

ah, gotcha