Error

Im getting this error in my code when trying to move a unit in my game not sure what it is could anyone help.

SendMessage SetSelected has no receiver!
UnityScript.Lang.UnityRuntimeServices:Invoke(Object, String, Object[ ], Type)
UnitSelection:Mouse1Up(Vector2) (at Assets/Scripts/UnitSelection.js:122)
UnitSelection:Update() (at Assets/Scripts/UnitSelection.js:36)

your using ‘SendMessage’ to send something to another script but that script isn’t found.

Isn’t it rather that the FUNCTION isn’t found ?

My little share and my little thoughts :slight_smile:

this is the code im using where the error is when i outline a group of unit in my rts and then click the ground thats when the error is generated

122 hit.collider.gameObject.SendMessage(“SetSelected”);

I believe AkilaeTribe is correct; no scripts attached to that GameObject have a method “SetSelected”. Double-check that you’re targeting the correct GameObject and that its scripts have the method (check for typos!).

If your calling method is a bit general (in that sometimes your targeted GameObject may have the method and other times not), you can use an overload of SendMessage that won’t fire the error:gameObject.SendMessage("SetSelection", SendMessageOptions.DontRequireReceiver);But don’t use this as a crutch to avoid the error. If you expect that your target GameObject is supposed to have the method, then you should let the error fire because it will alert you to a logical oversight in your code.

Heres the whole code . The GameObject should always be there when im using a terrain right?

function Mouse1Up(screenPosition : Vector2) {

mouseButton1UpPoint = screenPosition;
var hit : RaycastHit;

mouseLeftDrag = false;

if (IsInRange(mouseButton1DownPoint, mouseButton1UpPoint)) {

if (UnitManager.GetInstance().GetSelectedUnitsCount() == 0) {

ray = Camera.main.ScreenPointToRay (mouseButton1DownPoint);
if ( Physics.Raycast (ray, hit, raycastLength, nonTerrainLayerMask) )
{

hit.collider.gameObject.SendMessage(“SetSelected”);

}

} else {

UnitManager.GetInstance().MoveSelectedUnitsToPoint(mouseButton1DownTerrainHitPoint);
}
}
}

anyone know?

Terrains don’t have a function “SetSelected,” as everyone above said.
It looks like your code is trying to ignore the terrain, though, so unless your nonTerrainLayers var is incorrect you shouldn’t need to worry about terrains being there or not.
You need to only message gameObjects with that function or you need to DontRequireReceiver it.