事の発端
Unityにおいて,動的に読み込んだVRMモデルをFinal IKのFull Body Biped IK(FBBIK)を使って手とか足の位置を制御したかった.
VRM読み込み時にFBBIKをAddComponent.
そのFBBIKのleftHandEffectorとかのtargetを設定しようとしたら
IndexOutOfRangeException: Index was outside the bounds of the array.
RootMotion.FinalIK.IKSolverFullBodyBiped.GetEffector (RootMotion.FinalIK.FullBodyBipedEffector effector) (at Assets/Externals/Plugins/RootMotion/FinalIK/IK Solvers/IKSolverFullBodyBiped.cs:194)
と怒られた.
FBBIKのIKEffector[] effectorsが空のままになっているのが原因っぽい.
あらかじめインスペクタでFBBIKをアタッチしていると,この問題は発生しなかったのでAddComponentした場合はインスペクタからのアタッチ時には行われる何かが行われていないっぽい.
結論
AddComponentした後に以下の処理を追加する.
using RootMotion;
public FullBodyBipedIK fullBodyBipedIK;
fullBodyBipedIK = this.gameObject.AddComponent<FullBodyBipedIK>();
// ここから下の処理を追加
BipedReferences references = new BipedReferences();
BipedReferences.AutoDetectReferences(ref references, fullBodyBipedIK.transform, BipedReferences.AutoDetectParams.Default);
fullBodyBipedIK.SetReferences(references, null);
最初は肘曲げてないのが原因かな~とか思ってたけど違った.
あまり深く調査はしてないので参考までに.