In update, I wrote it to be where it searches for a gameobject with a tag “Enemy” on it.
but on start, nothing has that tag. I can play the game fine, but it just bugs me how the console keeps reading me errors. It says object reference not set to an instance of an object. This is what I wrote:
fpsTarget = GameObject.FindWithTag(“Enemy”).transform;
if (fpsTarget == null)
{
just to extend on this, if you use an assignment in a conditional like you have it’ll return “true” if it manages to succeed in that assignment, so in most instances it’ll always be returning true rather than throwing any errors.
exactly , it applies only the context of this unity related question , and unless implemented wont work , therefore becoming used to unity having the conversion check wil make you prone to making the mistake with those not implimented , but when you know the differences theres no issue .
Is it possible if I just exported the game and posted it on here? so you guys could just tell me what you would do to fix the problem?
the problem is, that just the console reading unatural errors. I can play the game just fine.
In void update, I make the npc search for a gameobject with a tag “Enemy” on it. But there wouldnt be a gameobject with the tag “Enemy” on it until I make an enemy.
so meanwhile, how should I satisfy the function that searches for the “Enemy” object?
I dunno how this thread got so derailed but - you’re trying to access the transform property from finding something tagged with Enemy. It doesn’t find anything so it throws an error. Split your Find(…) and .transform into two lines and check if the result of the Find() is null before proceeding.