Game.Rendering.InstancePropertyAttribute
Assembly: Assembly-CSharp (game code)
Namespace: Game.Rendering
Type: Attribute
Base: System.Attribute
Summary:
{{ The InstancePropertyAttribute is a custom attribute intended to annotate instance data/fields that should be bound to shader properties for GPU instancing rendering. It records the shader property name, the managed data type that backs the instance value, any required batch flags that must be present for the property to be used, an index for ordering or selecting among multiple data streams, and whether the property is a built-in engine property. This attribute is applied to fields (AttributeTargets.Field) and is primarily used by the rendering/instancing subsystem to discover and map per-instance data to shader inputs. }}
Fields
None
{{ This attribute does not declare explicit backing fields in source; it exposes its information via read-only properties. }}
Properties
-
public string ShaderPropertyName { get; protected set; }
{{ The name of the shader property (typically the name used in the shader, e.g., "_MyInstanceFloat") that this instance field should bind to. Readable publicly; the setter is protected and set by the constructor. }} -
public Type DataType { get; protected set; }
{{ The managed Type that represents the field's data (for example typeof(float), typeof(Vector4), or a custom struct). Indicates how the value should be interpreted/packed for the GPU. }} -
public BatchFlags RequiredFlags { get; protected set; }
{{ Flags that describe rendering batch requirements for this property. The BatchFlags enum (defined elsewhere in the rendering code) is used to indicate conditions or capabilities that must be present for the property to be active (default is 0, meaning no special requirements). }} -
public int DataIndex { get; protected set; }
{{ An integer index that can be used to select or order multiple instance data channels. Defaults to 0. }} -
public bool IsBuiltin { get; protected set; }
{{ When true, denotes that this property is considered a built-in/engine-level instance property rather than a user-defined one. Defaults to false. }}
Constructors
public InstancePropertyAttribute(string shaderPropertyName, Type dataType, BatchFlags requiredFlags = (BatchFlags)0, int dataIndex = 0, bool isBuiltin = false)
{{ Creates a new InstancePropertyAttribute and initializes all exposed properties:- shaderPropertyName: shader-side property name to bind to
- dataType: the managed System.Type of the instance data
- requiredFlags: optional BatchFlags mask indicating required features
- dataIndex: optional index for the data channel (default 0)
- isBuiltin: optional boolean marking the property as engine/builtin (default false)
This attribute is intended to be placed on fields so the renderer's reflection/registration code can discover instance properties and set up appropriate GPU buffers or shader bindings. }}
Methods
None
{{ The attribute class only contains property accessors and the constructor; it does not define additional methods. }}
Usage Example
// Example: annotate a field so the rendering system maps it to a shader property
public class MyInstanceData
{
[InstanceProperty("_MyInstanceColor", typeof(UnityEngine.Vector4))]
private UnityEngine.Vector4 instanceColor;
[InstanceProperty("_InstanceId", typeof(int), BatchFlags.UseInstanceIds, dataIndex: 1)]
private int instanceId;
}
// Reflection-based retrieval (simplified)
var field = typeof(MyInstanceData).GetField("instanceColor", BindingFlags.NonPublic | BindingFlags.Instance);
var attr = (InstancePropertyAttribute)Attribute.GetCustomAttribute(field, typeof(InstancePropertyAttribute));
if (attr != null)
{
// attr.ShaderPropertyName => "_MyInstanceColor"
// attr.DataType => typeof(UnityEngine.Vector4)
}
{{ Notes: - Apply this attribute only to fields (AttributeUsage is limited to fields). - The rendering/instancing subsystem will typically use reflection to collect these attributes at initialization and create GPU buffers or property blocks accordingly. - BatchFlags is an enum defined in the rendering codebase; check its definition to know which flags are available and when to use them. }}