- Home /
 
 
               Question by 
               JiveViking · Jul 03, 2020 at 06:27 PM · 
                guiinstantiateprefabslidertroubleshooting  
              
 
              Reference an instantiated UI publically
I am trying to create a healthbar UI using a slider, I want it to Instantiate above an enemy and I want the enemy script to reference that instance so that I can update its transform, I want to instantiate it in the start method and then update it's script in the update method.
 public Slider healthbar // prefab
 public Slider newHealthBar // I want to assign the instantiated one to this so that I can update it
 
 void Start() {
 newHealthBar = Instantiate(healthbar,Camera.main.WorldToViewportPoint(transform.position) , healthbar.transform.rotation, GameObject.FindGameObjectWithTag("Canvas").transform);
 }
 
               When I try to run this code it tells me that I am not assigning the reference
               Comment
              
 
               
              NullReferenceException: Object reference not set to an instance of an object Enemy.Start ()
I have also tried changing the reference type to GameObject, same error
 
               Best Answer 
              
 
              Answer by JiveViking · Jul 03, 2020 at 07:58 PM
I have figured out the issue in this case, I simply didn't set the canvas tag
Your answer