- Home /
Question by
wforkes · Jun 09, 2020 at 08:55 PM ·
instantiateparticlesnullreferenceexceptionscriptableobjectscriptable object
NullReference on trying to instantiate a prefab which has been set using scriptable object,Particle giving null reference but works in scene view
I have a scriptable object which holds a prefab of a particle effect.
This scriptable object is passed to a MonoBehavior but throws a null reference exception
public WeaponItem item;
public Transform camera;
public Transform gunPos;
public Transform firePos;
float elaspedTime = 0f;
float fireRate = 0f;
private void Start()
{
fireRate = 1f / item.fireRatePerSecond;
}
void Update()
{
if(Input.GetButton("Fire1"))
{
elaspedTime += Time.deltaTime;
if (elaspedTime >= fireRate)
{
Fire();
elaspedTime = 0f;
}
}
}
void Fire()
{
Instantiate(item.fireParticle, firePos);
//Destroy(fireParticle, 0.2f);
}
Here you can see that the particle is in fact set: https://i.gyazo.com/849fbe99c14d51e784e9b0e3a50decc3.png
And I all I get in return is: NullReferenceException: Object reference not set to an instance of an object
Comment
Your answer
Follow this Question
Related Questions
ScriptableObject reference resetted after a method is finished. 2 Answers
Instancing ScriptableObject not saved in assets results in warning message 0 Answers
Instantiate with random scriptableObject 2 Answers
Scriptable Object is getting set to null 0 Answers
Particles not Instantiating : NullReferenceException 1 Answer