Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Don't understand "Inconsistent Accessibility" error when passing Enum as parameter inside my method

Struggling to understand why I am getting the following error message –

Inconsistent Accessibility: Parameter type "GameModesMenu.GameMode" is less accessible than method "GameModesMenu.SelectedGameModeTextObject(GameMode _gameModeSelected)"

This is what my code looks like:

enum GameMode{None, PlayerVsAi1v1};

private GameMode gameModeSelected = GameMode.None;

public void PlayerVsAiOneVsOne()
{
    gameModeSelected = GameMode.PlayerVsAi1v1;
    SelectedGameModeTextObject(gameModeSelected);
}



public void SelectedGameModeTextObject(GameMode _gameModeSelected)
    {
        Debug.Log(_gameModeSelected);
        
    }

The error message goes away when I add the "public" access modifier to the enum like so:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public enum GameMode{None, PlayerVsAi1v1};

But I don’t understand why that works. I also don’t understand why I can access it with no problems within the methods, but the error only occurs when I pass it as a parameter.

>Solution :

Since the method is public, the enum parameter must also be public, so that it will be visible to the outer world.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading