#Hey there, I've created a heart system

1 messages · Page 1 of 1 (latest)

scarlet saffron
sick thicket
#

!code

oak ospreyBOT
scarlet saffron
#

        healthSystem heartComponent = newHeart.GetComponent<healthSystem>();
        heartComponent.SetHeartImage(HeartStatus.Full);
        hearts.Add(heartComponent);
    }

    public void DrawHearts()
    {
        ClearHearts();

        int heartsToMake = PlayerController.maxHealth;

        for (int i = 0; i < heartsToMake; i++)
        {
            Debug.Log("Drawing a heart");
            CreateFullHeart();
        }
    }


    public void ClearHearts()
    {
        foreach(Transform t in transform)
        {
            Destroy(t.gameObject);
        }

        hearts = new List<healthSystem>();  
    }



}

agile rose
#

What line has the error

scarlet saffron
#

1sec I'm figuring out the posting code stff

#

NullReferenceException: Object reference not set to an instance of an object
healthBar.CreateFullHeart () (at Assets/Scripts/healthBar.cs:36)
healthBar.DrawHearts () (at Assets/Scripts/healthBar.cs:49)
healthBar.Start () (at Assets/Scripts/healthBar.cs:16)

#

this is the first script I've posted that's giving the error

#

as visible in this screenshot references for heart prefab and player controller are set correctly

agile rose
#

Heartcomponent is null

#

Meaning that object doesn't have that component on it

scarlet saffron
#

oh I see, I'll look at that now, appreciate the help, will come back if I run into more errors.