- Home /
Is there a way to access the inspector fields (not the component properties) through a unity editor script?
Ok, this is a strange question. To be clear up front, I know that through an editor script I could just change values on the various component scripts directly, (e.g. transform.rotation = new Quaternion(0, 0.7f, 0, 0.7f);) but that's not going to work for my current situation.
I am trying to have an editor script rotate road objects by 90 degrees and am running into the floating-point issue. 90-degree rotations fall through whatever code path unity is using and come out the other end as 90.00001. And through trial and error, I have found that literally no attempt to set rotation through the transform avoids this. This leaves visible pixel lines that players can see between the rotated roads.
HOWEVER, I have also found that manually setting the rotation to 90 degrees in the inspector, DOES NOT hit this floating-point error. So through the inspector, there is a way around the floating point issue. But to get around it I would need an editor script to access the inspector fields rather than accessing the transform properties directly.
Is this possible? And if so how would I do it?
You might be able to achieve this through attributes and reflection coupled with a custom editor. I'm not well-versed in using custom editor scripts, but this video walks through reflection and how it can be used to expose certain properties. By exposing some rotation field using a custom attribute, you might be able to write a script that sets that field across all instances of a script.
Your answer
Follow this Question
Related Questions
How do I remove floating point errors when setting rotations with an editor script!? 2 Answers
Make a class who's public variables are 'unfurled' in the inspector, even whilst in an array. 1 Answer
How to specify the rotation angle in degrees, in the inspector? 2 Answers