Dynamic float not exposing in the inspector

I have been having trouble exposing the Dynamic float in the inspector for the unity event:

For some reason it is just not coming up. I have googled it a lot and it seems to be a bug that has come and gone in several versions of unity.

But to keep pushing on the just did it in code:
In the Health.cs:

public delegate void OnTakeDamageDelegate(float damage);
public OnTakeDamageDelegate onTakeDamage;

then add to the TakeDamage method: onTakeDamage(damage);

This is my DamageTextSpawner.cs (bit different to the lecture and nothing is in the DamageText.cs):

using UnityEngine;
using UnityEngine.UI;
using RPG.Resources;
namespace RPG.UI.DamageText
{
public class DamageTextSpawner : MonoBehaviour
{
[SerializeField] GameObject damageTextPrefab;

    private void OnEnable() 
    {
        GetComponentInParent<Health>().onTakeDamage += Spawn;            
    }
    private void OnDisable() 
    {
        GetComponentInParent<Health>().onTakeDamage -= Spawn;
    }

    public void Spawn(float damageText)
    {
        GameObject spawnedText = Instantiate(damageTextPrefab, transform.position, Quaternion.identity);
        Text text = spawnedText.GetComponentInChildren<Text>();
        text.text = damageText.ToString(); //if decimal places are an issue use string.format
        Destroy(spawnedText, 1f);
    }
}

}

I hope my work around helps. But I would like to know if there is a solution to the Dynamic float not appearing.

I don’t know if you noticed, but Spawn was listed in the graphic you posted.


I’m not sure why sometimes it doesn’t appear in the top.

Hi Brian,
Yes that is true, but it is not the Dynamic float which comes from the script, it is the float value entered in the inspector. The below image is what the course video shows:

Right, that’s what I was referring to on the not listed at the top. It seems to not work in every version of Unity, but the function is still available to select from the list.

Yes the function is still listed, but this takes the float variable from the value entered in the inspector in unity and not from the script (the Dynamic value). So it doesn’t matter what damage is calculated it will display the value entered in the inspector.

Ah, yes, I see what you mean. Forgot about that (Been a while since I watched the lecture). From what research I could do, it appears to be a bug in Unity that comes and goes as the versions change.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms