UEA0011: DoNotUseStringPropertyNames

October 5, 2019 ยท View on GitHub

PropertyValue
IdUEA0011
CategoryPerformance
SeverityWarning

Example

This is for both Material and Shader class methods. Both can be fixed by using Shader.PropertyToID() method.

Code with Diagnostic

class A : MonoBehaviour
{
    Shader shader;

    void Update()
    {
        shader.GetGlobalFloat("_Speed", 1f);
    }
}
class C : MonoBehaviour
{
    Material material;

    void Update()
    {
        material.SetVector("_WaveAndDistance", Vector3.one);
    }
}

Code with Fix

using UnityEngine;

class A : MonoBehaviour
{
    Shader shader;
    int speedHash;

    void Start() 
    {
        speedHash = Shader.PropertyToID("_Speed");
    }

    void Update()
    {
        shader.GetGlobalFloat(speedHash, 1f);
    }
}
using UnityEngine;

class C : MonoBehaviour
{
    Material material;
    int waveAndDistanceHash;

    void Start() 
    {
        waveAndDistanceHash = Shader.PropertyToID("_WaveAndDistance");
    }

    void Update()
    {
        material.SetVector(waveAndDistanceHash, Vector3.one);
    }
}