ERROR: Cannot Instantiate objects with a parent which is persistent

Following this course I get the following error message, when hitting an enemy, expecting damage text to fly up:

“Cannot Instantiate objects with a parent which is persistent. New object will be created without a parent.”

No text or anything.

Any ideas to what I’m doing wrong here?

Using Unity version 2020.3.20f1.

Paste in your DamageTextSpawner.cs script and we’ll have a look. Don’t forget to format it with the </> button.

1 Like
using UnityEngine;

namespace GoL.UI.DamageText
{
    public class DamageTextSpawner : MonoBehaviour
    {
        [SerializeField] DamageText _damageTextPrefab = null;

        public void Spawn(float damageAmount)
        {
            DamageText _inststance = Instantiate<DamageText>(_damageTextPrefab, transform);
            _inststance.SetValue(damageAmount);
        }
    }
}

Somehow missed the </> button on the first go, but there you are.

Is your Health component’s damage UnityEvent linking to the DamageTextSpawner attached to the character or to the DamageTextSpawner Prefab in the Assets?

2 Likes

It was the one from assets. I tried hooking it up with the one from Character and now it works again.

Thanks for the help!

2 Likes

Privacy & Terms