Unity crashes when trying to get some data from SerializedProperty.

Hello. I'm trying to use SerializedObject and SerializedProperty to access data of some objects, but trying to get data of type Vector2 consistently crashes unity when attempted on my test project. I do check propertyType, and it's Vector2, and I use vector2Value property to get data. I've tried putting this code inside try-catch block, doesn't change anything.

Another thing I can't figure out is how to get data for LayerMask type. Nothing seems to work.

Same here, it just crashes when doing something like this:

switch( serializedProperty.propertyType )
{
    case SerializedPropertyType.Vector2:
    Vector2 vector2 = serializedProperty.vector2Value;
    break;
}

Just use vector3Value and cast it to Vector2.

Vector2/3 work fine for me, but I’m on Unity 3.3, so perhaps things have been fixed since you asked your question.

I was in the same boat as you on the LayerMask – based on the docs I thought it would be an integer. I used ILSpy to look at the SerializedProperty class, and it turns out there are several internal members for dealing with layer masks, but nothing in the public API.

You can cheat using reflection though, like so:

using System.Reflection;
...
PropertyInfo pi = typeof(SerializedProperty).GetProperty("layerMaskStringValue", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic);
string layerMaskStringValue = pi.GetValue(serializedProperty, null);