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 failedFor 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 Your name Your email Suggestion*public string stringValue;
DescriptionValue of a string property.
Contains a valid value only if propertyType is SerializedPropertyType.String, otherwise accessing it results in an error logged.
Additional resources: propertyType, SerializedPropertyType.String.
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)); } }
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4