Why is this not working?

My animation is all in one so I am trying to seperate it. Here is the code for that:

document.body.onclick=function(){
var anim = en.entity.animation.getAnimation('FireGun');
anim.firstFrame = 0;
anim.lastFrame = 8;
en.entity.animation.play("FireGun");
};

But I can’t get it to work. Can you help me or suggest a better way? Thanks!
here is the link:
https://playcanvas.com/editor/project/747902

firstFrame and lastFrame are not valid properties for the Animation object as shown by the API docs https://developer.playcanvas.com/en/api/pc.Animation.html

You will have to start digging into the engine source code to work out what is needed to play a sub set of the animation.

Not quite sure what that means but ok…

Can you please explain what you mean by that?

Okay, to put it another way: where do you see firstFrame and lastFrame in the PlayCanvas documentation?

I didn’t. I got it from here:


I am really just trying to split an animation without the use of any other software.

I believe that post modified the engine with the patch code in that post which changes how the engine works. If you haven’t added that patch to the project, the code you have posted will not work.

Also bear in the mind that the engine code may have changed since 3 years ago so the patch may no longer work anyway.

Are there any other options?
All the skethfab gun models have all the animations put together.

Like whydoidoit did, you will have to dig into the engine source and work out what you would need to change/patch to get the functionality you need.

Or contact the original animator of the file you are using to upload a version with the animations split.