float GetFloat( Sandbox.StringToken& name, System.Single& defaultValue )

book_4_sparkGenerated
code_blocksInput

Description

The GetFloat method in the RenderAttributes class is used to retrieve a floating-point value associated with a specific attribute name. If the attribute is not found, it returns a default value provided by the caller.

Usage

To use the GetFloat method, you need to pass a StringToken reference that represents the name of the attribute you want to retrieve. Additionally, you must provide a reference to a float that serves as the default value in case the attribute is not found.

This method is useful when you need to access rendering attributes that are stored as floating-point numbers, ensuring that you have a fallback value if the attribute is not set.

Example

RenderAttributes renderAttributes = new RenderAttributes();
StringToken attributeName = new StringToken("exampleAttribute");
float defaultValue = 1.0f;
float result = renderAttributes.GetFloat(ref attributeName, ref defaultValue);

// result now holds the value of 'exampleAttribute' or 1.0f if not found.