mhart ian cruz mhart ian cruz - 1 year ago 72
C# Question

No overload for method `CharacterSave' takes `1' arguments

I got this error when I upgraded my project to the newest Unity version..

Don't know which part am I wrong . But here's my snips of my code

CharacterModule.cs

var prefab = Instantiate(characterData).GetComponent<Player>();
prefab.name = characterName;
prefab.account = user.Username;
prefab.className = request.ClassName;
prefab.transform.position = gameConfig.startPosition;
prefab.health = prefab.healthMax;
prefab.mana = prefab.manaMax;
Database.CharacterSave(prefab);
Destroy(prefab.gameObject);

var gameUser = GameUserModule.Database.Get(user.Username);
if (gameUser == null)
{


GameMapnetwork.cs

// add to client
NetworkServer.AddPlayerForConnection(connection, go, 0);
}

public void SaveCharacters()
{
if (!NetworkServer.active)
return;

Database.CharacterSaveMany(Player.onlinePlayers.Values.ToList());
}

public void SaveCharacter(Player player)
{
Database.CharacterSave(player);
}


GameModule.cs

var go = Database.CharacterLoad(name, GameConfig.Instance.GetPlayerClasses());
if (go == null)
{
message.Respond("Character not found", ResponseStatus.Failed);
return;
}
var player = go.GetComponent<Player>();

var gameUser = gameUserDatabase.Get(user.Username);
if (gameUser == null)
{
gameUser = GameUserModule.Database.CreateObject(user.Username);
gameUserDatabase.Insert(gameUser);
}
gameUser.SelectedCharacter = name;
gameUserDatabase.Update(gameUser);

string resultMap = player.savedCurrentMap;
Vector3 resultPosition = player.transform.position;

if (string.IsNullOrEmpty(resultMap))
{
resultMap = player.savedCurrentMap = GameConfig.Instance.startScene;
resultPosition = player.transform.position = GameConfig.Instance.startPosition;
Database.CharacterSave(player);
}

Destroy(player.gameObject);

if (mapCallback != null)
mapCallback(resultMap, resultPosition);


Here's some body of my code. I don't know which part is wrong. I am really appreciate you help!

Answer Source

Basically that error you mention is telling you that you haven't define a method called CharacterSave with a single parameter in its parameter list. Something like:

CharacterSave(paramType paramName)

You should show us where you implement the method:

CharacterSave(...)

It could also be you just mixed names with the overloaded method SaveCharacters:

SaveCharacters()
SaveCharacter(Player player)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download