Hey,
Ever since I updated to the latest Unity, I keep getting these errors:
WARNING: This method could return default value implicitly.
When I click on them, they bring me to some of my functions names. But I don’t know what this means. Anyone have this problem and solved it?
Can you post an example of a function where this happens?
//Place enemies at random Spawn points
function Spawner(){
for (var index = Random.Range (0, numEnemies); index < numEnemies; ++index){ // Loop through the pool of enemies.
if (totalEnemies [index].isAvailable){ // If the current enemy isn't active, it's free to use
// Get a random spawn point
spawnPointIndex = Random.Range(0, spawnPoints.Length);
if (spawnPoints[spawnPointIndex].renderer.enabled == true){
// Activate the enemy.
totalEnemies[index].gameObject.SetActiveRecursively(true);
totalEnemies [index].isAvailable = false;
totalEnemies [index].isActive = true;
totalEnemies[index].howManySpawns++;
//position it enemy at a random spawn point
totalEnemies [index].transform.position = spawnPoints[spawnPointIndex].transform.position;
// Increase enemies.
numberOfEnemies++;
// Adds to the amount in the enemy waves
waveAmount++;
//returns the enemy
return totalEnemies[index];
}else{
spawnPointIndex = Random.Range(0, spawnPoints.Length);
return spawnPointIndex;
}
}
}
}
It points to “function Spawner()” when I click on it.
No one is having these warning errors?
add : int to the function declaration. You return an int but don’t specifiy the function to do so, so it declares the int return implicitely and warns about it as it can bite your ass under pragma strict / mobile if you try to assign it to a float and alike
Could you write out what you are describing? Thanks!
Change
//Place enemies at random Spawn points
function Spawner(){
To
//Place enemies at random Spawn points
function Spawner() : int{
Hmm…I got this error :
Cannot convert 'EnemyControls' to 'int'.
EnemyControls is the name of my other script.
It seems to be having a problem with my list variable now:
var totalEnemies = new List.<EnemyControls>()
??
I am still getting these warnings…
Anyone?
EDIT: nvm, I just removed the return part of the script and the warnings dont show anymore. I just dont understand how/when to use returns, thats all…
returns are what you return from return XXX and it always has to be the same datatype
if you get a warning you shouldn’t remove the return type but either specify it correctly or fix the function that does not always return data in the correct data type 
Actually, removing the returns scripts from my functions caused the game to not function properly, so mike_mac told me to leave my returns where they are and just add:
return null;
to the last line of my function:
//Place enemies at random Spawn points
function Spawner(){
for (var index = Random.Range (0, numEnemies); index < numEnemies; ++index){ // Loop through the pool of enemies.
if (totalEnemies [index].isAvailable){ // If the current enemy isn't active, it's free to use
// Get a random spawn point
spawnPointIndex = Random.Range(0, spawnPoints.Length);
// Activate the enemy.
totalEnemies[index].gameObject.SetActiveRecursively(true);
totalEnemies [index].isAvailable = false;
totalEnemies [index].isActive = true;
totalEnemies[index].howManySpawns++;
//position it enemy at a random spawn point
totalEnemies [index].transform.position = spawnPoints[spawnPointIndex].transform.position;
// Increase enemies.
numberOfEnemies++;
// Adds to the amount in the enemy waves
waveAmount++;
//returns the variables
return totalEnemies [index];
}
}
return null;
}