Displaying attributes names

Haytam95

Active member
Hi

I'm extending some of the default abilities (Here you can see an example of Sprint using stamina: https://www.opsive.com/forum/index.php?threads/sprint-using-stamina.1860/) and i wanted to know how to serialize attributes names.

Like this:

1571698429270.png

In the code i found out that it's using a string variable, to fetch the attribute:

C#:
[Tooltip("The name of the health attribute.")]
[SerializeField] protected string m_HealthAttributeName = "Health";

// More code....

public string HealthAttributeName { get { return m_HealthAttributeName; }
    set {
        m_HealthAttributeName = value;
        if (Application.isPlaying) {
            if (!string.IsNullOrEmpty(m_HealthAttributeName)) {
                m_HealthAttribute = m_AttributeManager.GetAttribute(m_HealthAttributeName);
            } else {
                m_HealthAttribute = null;
            }
        }
    }
                   
/// More Code

private Attribute m_HealthAttribute;

public Awake() {
    if (!string.IsNullOrEmpty(m_HealthAttributeName)) {
        m_HealthAttribute = m_AttributeManager.GetAttribute(m_HealthAttributeName);
    }
}


I've copied the same code structure, but my inspector won't serialize the field as above. It just print a simple field:

1571698748596.png


Here is my code:

C#:
[Tooltip("Propiedad de stamina que se usará para consumir")]
[SerializeField]
protected string attributeStaminaName = "Stamina";

// More code...

public string AttributeStaminaName {
    get => attributeStaminaName;
    set {
        attributeStaminaName = value;
        if (!Application.isPlaying) return;
        if (!string.IsNullOrEmpty(attributeStaminaName)) {
            m_AttributeStamina = m_AttributeManager.GetAttribute(attributeStaminaName);
        }
        else {
            m_AttributeStamina = null;
        }
    }
}


private Attribute m_AttributeStamina;

// More code

public override void Awake() {
    base.Awake();

    m_AttributeManager = GetComponent<AttributeManager>();
    if (!string.IsNullOrEmpty(attributeStaminaName)) {
        m_AttributeStamina = m_AttributeManager.GetAttribute(attributeStaminaName);
    }
    
}



I'm missing something? Thanks!


P.S: This is an ability, so the inspector is already serializing another field filtering the attributes names. Maybe this is the problem?

1571698820548.png

(Sprint extends ChangeSpeed ability)
 
Instead of serializing do you mean displaying? The attribute names are displayed using the InspectorUtility.DrawAttribute method.
 
Instead of serializing do you mean displaying? The attribute names are displayed using the InspectorUtility.DrawAttribute method.

Yes you're right, i mean displaying. (Sorry! Not english native speaker)

I'll look out at that method, thank you Justin
 
Top