Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


SetText

Sets the text content without allocating a managed string.
Read time 1 minuteLast updated 12 days ago

Definition

SetText(ReadOnlySpan<char>)

Sets the text content without allocating a managed string.
public void SetText(ReadOnlySpan<char> text)

Parameters

The character span to set as the element's text content.

Remarks

Unlike assigning to _text, this method writes directly into an internal native buffer and defers string materialization until _text is read. A ChangeEvent<T> of type
string
is raised only when listeners for value-change events exist in the element's hierarchy; when no such listeners are present, the method is fully allocation-free.

SetText(char[], int, int)

Sets the text content from a character array slice without allocating a managed string.
public void SetText(char[] sourceText, int start, int length)

Parameters

sourceText

The source character array.

start

The starting index in the array.

length

The number of characters to copy.

SetText(StringBuilder)

Sets the text content from a StringBuilder without allocating a managed string.
public void SetText(StringBuilder sb)

Parameters

The StringBuilder whose contents to copy.

SetText(float, string)

Formats a float value directly into the text buffer without allocating a managed string.
public void SetText(float value, string format = null)

Parameters

value

The float value to display.

format

An optional standard or custom numeric format string.

SetText(int)

Formats an integer value directly into the text buffer without allocating a managed string.
public void SetText(int value)

Parameters

value

The integer value to display.