Error

NullReferenceException: Object reference not set to an instance of an object
what does this error mean?

objectDisplay.ViewObject(transform.gameObject, treeHealth, MaxTreeHealth, 0.25f);
the line with the function call

public void ViewObject(GameObject displayedObject, int objectHealth, int objectMaxHealth, float objectResurs)
the line with the function declaration

it means some variable you used didnt get set to anything so it couldnt do itā€¦ in the case likely objectDisplay

1 Like

A variable or field on that line currently has a value of null.

I understand this, but as a transform.The GameObject can be empty if it is the object to which the script is attached

Itā€™s most likely not the transform. Weā€™d have to see actual code to be able to help more.

I am having a doubt, can I ask a question?

Ok, thanks.

Please donā€™t necro-post. If you have a new question, make a new post. Itā€™s FREE!!

If all you have is a null reference, you donā€™t need to post because:

The answer is always the sameā€¦ ALWAYS!

How to fix a NullReferenceException error

https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

Three steps to success:

  • Identify what is null ā† any other action taken before this step is WASTED TIME
  • Identify why it is null
  • Fix that

If you have an actual question, when you post, remember we cannot read your mind and we cannot see your screen.

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you havenā€™t put effort into finding the documentation, why should we bother putting effort into replying?

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379