Property | Value |
---|---|
Id | UEA0002 |
Category | GC |
Severity | Info |
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);
}
}
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);
}
}