LoginSignup
0
0

More than 5 years have passed since last update.

InvalidOperationException: The operation is not possible when moved past all properties (Next returned false)

Last updated at Posted at 2016-09-27

自分のブログの記事

というわけで表題のエラーの話

今回はEditorGUI.PropertyFieldでVector3型を表示しようとしてできなかったので対応した話。

// ここで表題のエラーが出る
EditorGUI.PropertyField(rect, action.FindPropertyRelative("targetPosition"));

action.FindPropertyRelative("targetPosition")はVector3型が格納されている
action.FindPropertyRelative("targetPosition").vector3value等を見ると正常に取れている事がわかる

EditorGUI.PropertyField(rect, action.FindPropertyRelative("targetPosition"));
を使いたいけど表題のエラーが出てうまくいかない場合は以下のように直す事で解決ができる。

action.FindPropertyRelative("targetPosition").vector3Value = EditorGUI.Vector3Field(rect, "hoge", action.FindPropertyRelative("targetPosition").vector3Value);

しかし厳密な解決じゃないというか
例えば

var properties = new string[] { "hoge", "fuga", "targetPosition" };
foreach (var p in properties)
{
    EditorGUI.PropertyField(rect, action.FindPropertyRelative(p));
}

のようにしたい場合にこまるかもしれない。
1つ2つの例外ならいいかもしれないけどそうもいかないとおもう。

そこについては解決したらまたなんか描きます

追記


var properties = new string[]{"hoge", "fuga", "targetPosition"};

foreach (var p in properties)
{
    var property = action.FindPropertyRelative(p);
    switch(property.propertyType)
    {
        case SerializedPropertyType.Vector3:
            property.vector3Value = EditorGUI.Vector3Field(rect, property.displayName, property.vector3Value);
            break;
        default:
            EditorGUI.PropertyField(rect, property);
            break;
    }
}

これで良さそう

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0