Some basic Scripting Troubles in C# null reference

I have a bool called “WeaponTrail” on my animator which is on the current game object. I am using the XWeaponTrail asset, and am trying to turn the weapon trail off and on for each melee swing (each attack animation state). The sword has the weapon trail attached to it. The sword is attached to the model, which is all on the same game object like normal. I am recieving a null reference exception with the following code. I’m pretty new in coding, any help would be appreciated.

using UnityEngine;
using System.Collections;
using Xft;

public class SwordTrailSwitch : MonoBehaviour {
	XWeaponTrail xwep;
	Animator anime;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		Swordbool ();
	}

//CGP turn on and off weapon trail CGP
void Swordbool()
	{
		if (anime.GetBool ("WeaponTrail") == true) {
			xwep.Activate ();
		} 
		if(anime.GetBool("WeaponTrail") == false) {
			xwep.Deactivate ();
		}


	}
}

Are you trying to activate the sword trail as a game object? If that is the case you need xwep.SetActive(true) and xwep.SetActive(false) respectively. Hope this helped, if not let me know and put the error message in here too, it helps understand the issue for us. :slight_smile: