Skip to content

Latest commit

 

History

History
57 lines (46 loc) · 1.06 KB

File metadata and controls

57 lines (46 loc) · 1.06 KB

UEA0002: DoNotUseStringMethods

Property Value
Id UEA0002
Category GC
Severity Info

Example

Code with Diagnostic

using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        // UEA0002: Using string methods can lead to code that is hard to maintain
        gameObject.SendMessage("ApplyDamage", 5.0);
    }
}

public class Example2 : MonoBehaviour
{
    public void ApplyDamage(float damage)
    {
        print(damage);
    }
}

Code with Fix

Use of SendMessage, SendMessageUpwards, BroadcastMessage, Invoke or InvokeRepeating leads to code that is hard to maintain. Consider using UnityEvent, C# event, delegates or a direct method call.

using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        var obj = GetComponent<Example2>();
        obj.ApplyDamage(5.0);
    }
}

public class Example2 : MonoBehaviour
{
    public void ApplyDamage(float damage)
    {
        print(damage);
    }
}