WARNING: This method could return default value implicitly.

I got this warning on several functions. I read in Unity Answes that I should define the type that the function returns (I don’t know why, all the other functions work properly without type defining). So this is the function:

	function Axis(){
		if(type == SBIType.Key) return axisInterpolation;
		else if(type == SBIType.Axis){
			if(positive != ""  negative != "") return (Input.GetAxisRaw(positive) + Input.GetAxisRaw(negative))/2;
			else if(positive != "")  return Input.GetAxisRaw(positive)*1.0f;
			else if(negative != "")return Input.GetAxis(negative)*1.0f;
		} else return 0.0f;
	}

The warning won’t go away even if I define the return type:

function Axis() : float{ ...

Also if I make the function like that:

	function Axis() : float{
		var axis : float = 0.0f;
		if(type == SBIType.Key) axis = axisInterpolation;
		else if(type == SBIType.Axis){
			if(positive != ""  negative != "") axis = (Input.GetAxisRaw(positive) + Input.GetAxisRaw(negative))/2;
			else if(positive != "")  axis = Input.GetAxisRaw(positive)*1.0f;
			else if(negative != "")axis = Input.GetAxis(negative)*1.0f;
		} 
		return axis;
	}

The warning will disappear…

I want to know what’s actually happening here. Can somebody shed some light ? :slight_smile:
Cheers!

I wouldnt recommend you to make the returns inside of ifs, instead declare a “result” variable in the first line of the function, set it through out the function, and in the end return it.

You need an unconditional return value to clear that error. Your first example code using “else return 0.0f;” should just read as “return 0.0f;”. As “else return 0.0f;” can’t be evaluated to a fixed path and might branch to logic that won’t return anything which is what that error means.

Right! Thanks for the info! I never realised that. So I either have to use a result value or have an unconditional return.