Error CS7036: There is no argument given that corresponds to the required formal parameter 'icon' of 'kod.kod(string, bool, Sprite)'

Hi, i want to cra=eate list of objects, but it doesn’t work.
my code:

public class obj
{

public string name;
public Sprite icon;
public bool WasUnlocked;

public obj( ){   }

public obj(string name , bool WasUnlocked , Sprite icon)
{
    this.name = name;
    this.icon = icon;
}

}

public List<obj> codesList= new List<obj>
    {
          new kod("code1" , Resources.Load<Sprite>("grafika/icons/map"))
        , new kod("code2" , Resources.Load<Sprite>("grafika/icons/map"))
    };

Thanks for every reply.

You posted the class for obj and the error clearly says kod

You can fix your own typing mistakes. Here’s how:

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

I changed a few things in the code before adding this topic to make it easier to read, but I also forgot to change the error message (Sorry for this mistake). Also i tried lookink for people with the same problem first, but none of the things that were shown on stack overflow, or other topics in unity disscusion seemed to work, so i have decided to ask
about my problem.

Well post the code because above you’re posting two constructors for kod() that take TWO arguments (count them yourself) and you’re posting a class with a 0-argument and a 3-argument constructor.

There are TWO arguments in this constructor call:

Again, your problem is nothing special, you just are not using C# correctly. If you cannot immediately see this from what I posted so far, you may wish to set your game project aside and work through some C# programming tutorials first.

None of this is magic but you MUST pay attention to details.

Imphenzia: How Did I Learn To Make Games:

1 Like
  1. Thanks for help.
  2. You are probably right, and i need to focus more on learning , and not jumping straight to the project.

It may also be helpful to think of the compiler NOT as your enemy but rather as your helper.

The compiler is after all the only thing standing between complete gibberish and a possibly-functioning program (the compiler CANNOT make your code correct, but it will enforce language syntax), so when it says something is wrong, take it at its word and seriously begin your investigation.

YES, yes, there are plenty of ways we can confuse ourselves (I do it all the time and I’ve been coding for over 40 years!), but the key is to recognize that when the compiler says “problem!” just assume the compiler is correct.

The compiler is almost always correct in 2024.

1 Like