How to save all joint positions (transform.position) of a skeleton in play-mode,How to save skeleton joint positions (transform.position) for each frame in play mode?
Hi,
I was hoping to be advised on how to save the pose (transform.position) of a skeleton at each frame during play-mode into a json/txt file.
This is what I have so far, and it does not seem to work as the json file only contains an empty dict.
void Start () {
// delete folder (and anything inside it) if it exists
// if( System.IO.Directory.Exists(SaveLocation) ){
// System.IO.Directory.Delete(SaveLocation, true);
// }
// create the folder for dumps
// System.IO.Directory.CreateDirectory(SaveLocation);
// initialize frame counter to 0
numberOfFrames = 0;
}
void Update() {
List<Vector3> listOfPos = new List<Vector3>();
if (Time.frameCount <= numberOfFrames){
Action<Bone> recursion = null;
recursion = new Action<Bone>((bone) => {listOfPos.Add(new Vector3 (bone.Transform.position.x, bone.Transform.position.y, bone.Transform.position.z));
// Debug.Log(bone.Transform.position);
for(int i=0; i<bone.Childs.Length; i++) {
recursion(bone.GetChild(i));
}
});
if(Bones.Length > 0) {
recursion(Bones[0]);
}
}
// StreamWriter sw = new StreamWriter(@"/Users/xiaohanzhang/filedumps.txt");
// sw.WriteLine("" + listOfPos);
// sw.Close();
string json = JsonUtility.ToJson(listOfPos);
File.WriteAllText("/Users/xiaohanzhang/filedumps.json" , json );
numberOfFrames++;
}
Many thanks!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612222907im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I make an object transform to given position and rotation 2 Answers
How to tell what method is moving an object? 3 Answers
How to transform position of one object to the exact position of another object? 0 Answers
Colliders have a different postion to wheels want to reset colliders to have new postion origin 0 Answers
If two Vector2 are same 1 Answer