- Home /
Access another objects property in an editor script
I'm trying to write an editor script for one of my objects. I'd like to enforce some constraints for some of the fields but some the values for these constraints live on other objects.
When i query the scene and access that instance they don't return the correct value. I'm guessing because found object is not the serialized version of itself it does not return its inspector value.
I was wondering if there is a way to do this kind of thing?
Edit:
Maybe there is better way of doing it but I found a way to accomplish what I need. Below code goes into the editor script. I create an editor for the other object and get its inspector value.
var obj = FindObjectOfType<type>();
var objEditor = Editor.CreateEditor(obj);
var constraintValue = objEditor.serializedObject.FindProperty("PropertyToFind").intValue;
Answer by khos85 · Jan 23, 2015 at 09:56 PM
I have little experience with this but have you looked the getcomponent method?
Your answer
Follow this Question
Related Questions
Can I serialize data in an Editor class? 1 Answer
Is it possible to display a List of GameObject List in a Custom Inspector? 1 Answer
Is there a way to get the names of all SerializedProperty objects in a SerializedProperty object? 1 Answer
How to create a lightweight Item/Mineral/etc System 1 Answer