Suggest a change
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Close
Submission failed
For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Close
public string stringValue;
Description
Value of a string property.
using UnityEditor;
using UnityEngine;
public class SerializedPropertyStringExample2
{
[MenuItem("Example/SerializedProperty stringValue Get Example")]
public static void PrintStringProperties()
{
// Retrieve the currently selected Scene object in the Hierarchy Window,
// or Asset selected in the project view
var selectedObject = Selection.activeObject;
if (selectedObject == null)
{
Debug.Log("No object selected.");
return;
}
SerializedObject serializedObject = new SerializedObject(selectedObject);
// Get the base property
SerializedProperty property = serializedObject.GetIterator();
// Move to the first property
bool visitChildren = true;
property.NextVisible(visitChildren);
visitChildren = false;
// Iterate through all the top level properties (not recursive)
do
{
if (property.propertyType == SerializedPropertyType.String)
{
Debug.Log($"Property: {property.name}, Value: {property.stringValue}");
}
}
while (property.NextVisible(false));
}
}