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?


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;

I have little experience with this but have you looked the getcomponent method?