Changing sprite renderer color not working?

In my game, the player has the option to throw their ‘sword’ towards others. When they do this it creates a thrown sword prefab and assigns it the ID number of the player who threw it, which it uses to reference a global array containing the color tints for all the players. But for some reason, it isn’t working for me. It spits out the error,
NullReferenceException: Object reference not set to an instance of an object
ThrownSwordController.SetPlayer (Int32 p) (at Assets/Scripts/ThrownSwordController.cs:40)
PlayerController.Update () (at Assets/Scripts/PlayerController.cs:64)

Here’s my code in the thrown sword object

//Set the associated player for this sword
public void SetPlayer(int p) {
    associatedPlayer = p;
    rend.color = Pallete.playerColors [p];
}

(Where Pallete is a class with some static variables)

And the player object

ThrownSwordController swordCon = swordGO.GetComponent<ThrownSwordController> ();
    if (swordCon) {
    swordCon.SetPlayer (playerNum);
    swordCon.SetMotion (swordPivot.right * throwForce);
}

Any help would be appreciated! Thanks

Either rend or Pallete.playerColors has not been assigned a value.

That makes sense, except in the sword code I also have a bit to make it fade to grey after a few seconds in an IENumerator

//Adjust color
for (float i = 0; i < duration; i += Time.deltaTime) {
    rend.color = Vector4.Lerp(Pallete.playerColors[associatedPlayer],Pallete.deadColor,i/duration);
    yield return null;
}

This bit works fine if I don’t assign the color earlier on

Are you certain that rend is assigned before trying to assign the color though?

This is all going off an assumption that this is the line causing your errors:

rend.color = Pallete.playerColors [p];

It probably is, since the color is being assigned almost immediately after instantiation. I’ll try moving the renderer initialization code to the Awake method instead of Start

EDIT: Yep, that fixed it. Thanks!