Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a sensible value for animation component duration if no animation is playing #4765

Merged
merged 6 commits into from
Oct 19, 2022
Merged
10 changes: 8 additions & 2 deletions src/framework/components/animation/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Skeleton } from '../../../scene/animation/skeleton.js';
import { Asset } from '../../asset/asset.js';

import { Component } from '../component.js';
import { revision, version } from "../../../core/core.js";

/** @typedef {import('../../../scene/animation/animation.js').Animation} Animation */
/** @typedef {import('../../../scene/model.js').Model} Model */
Expand Down Expand Up @@ -216,12 +217,17 @@ class AnimationComponent extends Component {
}

/**
* Get the duration in seconds of the current animation.
* Get the duration in seconds of the current animation. Returns 0 if no animation is playing.
*
* @type {number}
*/
get duration() {
return this.animations[this.currAnim].duration;
if (this.currAnim) {
return this.animations[this.currAnim].duration;
}

Debug.warn(`No animation is playing to get a duration. Returning 0.`);
return 0;
}

/**
Expand Down