Building a custom in game console - error CS0534; does not implement inherited abstract

Hello fellow developers

Im running into a few errors. I am trying to write a console for my game. I followed a youtube tutorial

I have to remove override from public override string cName { get; protected set; } and other variables to get anything to work then I start to get this error.

Assets/Scripts/Console/CommandQuit.cs(7,15): error CS0534: InGameConsole.CommandQuit' does not implement inherited abstract member InGameConsole.ConsoleCommand.cName.get

CommandQuit.cs

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

namespace InGameConsole
{
    public class CommandQuit : ConsoleCommand
    {
        public override string cName { get; protected set; }
        public override string cCommand { get; protected set; }
        public override string cDescription { get; protected set; }
        public override string cHelp { get; protected set; }

        public CommandQuit()
        {
            cName = "Quit";
            cCommand = "quit";
            cDescription = "Quits the application";
            cHelp = "Use this command with no arguments to force Unity to quit!";

            AddCommandToConsole();
        }

        public override void RunCommand()
        {
            if (Application.isEditor)
            {
                #if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
                #endif
            }
            else
            {
                Application.Quit();
            }
        }

        public static CommandQuit CreateCommand()
        {
            return new CommandQuit();
        }
    }
}

DeveloperConsole.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace InGameConsole
{

    public abstract class ConsoleCommand
    {
        public abstract string cName { get; protected set; }
        public abstract string cCommand { get; protected set; }
        public abstract string cDescription { get; protected set; }
        public abstract string cHelp { get; protected set; }

        public void AddCommandToConsole()
        {
            string addMessage = " command has been added to the console.";

            DeveloperConsole.AddCommandsToConsole(cCommand, this);
            DeveloperConsole.AddStaticMessageToConsole(cName + addMessage);
        }

        public abstract void RunCommand();
    }

    public class DeveloperConsole : MonoBehaviour
    {
        public static DeveloperConsole Instance { get; private set; }
        public static Dictionary<string, ConsoleCommand> Commands { get; private set; }

        [Header("UI Components")]
        public Canvas consoleCanvas;
        public ScrollRect scrollRect;
        public Text consoleText;
        public Text inputText;
        public InputField consoleInput;

        private void Awake()
        {
            if(Instance != null)
            {
                return;
            }

            Instance = this;
            Commands = new Dictionary<string, ConsoleCommand>();
        }

        private void Start()
        {
            consoleCanvas.gameObject.SetActive(false);
            CreateCommands();
        }

        private void CreateCommands()
        {
            CommandQuit commandQuit = CommandQuit.CreateCommand();
        }

        public static void AddCommandsToConsole(string _name, ConsoleCommand _command)
        {
            if(!Commands.ContainsKey(_name))
            {
                Commands.Add(_name, _command);
            }
        }

        private void Update()
        {
            //if(Input.GetKeyDown(KeyCode.BackQuote))
            //{
            //    consoleCanvas.gameObject.SetActive(!consoleCanvas.gameObject.activeInHierarchy);
            //}

            if(consoleCanvas.gameObject.activeInHierarchy)
            {
                if(Input.GetKeyDown(KeyCode.Return))
                {
                    if(inputText.text != "")
                    {
                        AddMessageToConsole(inputText.text);
                        ParseInput(inputText.text);
                    }
                }
            }
        }

        private void AddMessageToConsole(string msg)
        {
            consoleText.text += msg + "\n";
            scrollRect.verticalNormalizedPosition = 0f;
        }

        public static void AddStaticMessageToConsole(string msg)
        {
            DeveloperConsole.Instance.consoleText.text += msg + "\n";
            DeveloperConsole.Instance.scrollRect.verticalNormalizedPosition = 0f;
        }

        private void ParseInput(string input)
        {
            string[] _input = input.Split(null);

            if (_input.Length == 0 || _input == null)
            {
                AddMessageToConsole("Command not recognized.");
                return;
            }

            if (!Commands.ContainsKey(_input[0]))
            {
                AddMessageToConsole("Command not recognized.");
            }
            else
            {
                Commands[_input[0]].RunCommand();
            }
        }
    }
}

What do you mean “to get anything to work”? The posted code compiles, so what is the error you get with it?

You may want to look into abstract, but the simple answer is you must override and implement the abstract stuff when you inherit from that class.

umm so unity is very odd. So all i did to fix this is delete and re-typed override on the public variables. and its working now… smh WHAT!!

When override was in the public variables originally it would give a error saying it was not suitable or something to that effect. so i removed it from the declaration which seamed to make it not give that error but threw the error that was in my original post… idk its working now so im not going to question it. lol

public override string cName { get; protected set; }
public override string cCommand { get; protected set; }
public override string cDescription { get; protected set; }
public override string cHelp { get; protected set; }

1 Like

bad choice of words