I keep getting this error and I’ve had this error through the duration that I’ve been making my game but I’ve never really look notice of it since it didn’t seem to effect my game. However I believe it’s big reason behind massive lag issues within my game but I’m just not sure how to fix it.
This is the error:
and it’s point to my Entity Script:
using UnityEngine;
using System.Collections;
public abstract class Entity : MonoBehaviour {
protected Rigidbody2D rig;
protected Animator anim;
protected SpriteRenderer spriteRenderer;
protected ObjectPooler objectPooler;
private float beyondScreenDelay = 5f;
protected virtual void Awake()
{
rig = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
spriteRenderer = GetComponent<SpriteRenderer>();
}
protected virtual void Update()
{
if(!GetComponent<SpriteRenderer>().isVisible)
{
DestroyOffScreen();
}
}
protected void DestroyOffScreen()
{
beyondScreenDelay -= Time.deltaTime;
if(beyondScreenDelay <= 0f)
{
objectPooler.DestroyPooledObject(this.gameObject);
beyondScreenDelay = 5f;
}
}
}
“objectPooler.DestroyPooledObject(this.gameObject);” is simply point to this method in my Object Pooler class:
public void DestroyPooledObject(GameObject obj)
{
obj.SetActive(false);
}
I’ve got this issue for multiple objects and points to the same method but within different scripts. I’ve got the same error for my player projectile pointing to this class and method:
public class PlayerBullet : Projectile {
protected override void OnDestroy ()
{
objectPooler.DestroyPooledObject(this.gameObject);
}
}
Can anyone help me fix this error?