Skip to content

Commit

Permalink
Return a sensible value for animation component duration if no animat…
Browse files Browse the repository at this point in the history
…ion is playing (#4765)

* Processing the animation data properties in the original order before PR #4174

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

* Return max value instead

* Reverting value to 0 with warning

* Update src/framework/components/animation/component.js

Co-authored-by: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com>

Co-authored-by: Steven Yau <syau@snapchat.com>
Co-authored-by: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 19, 2022
1 parent 767e141 commit 8077ae5
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit 8077ae5

Please sign in to comment.