prefetchAnimation undefined


#1

I’m working on an interface script that displays a HUD to the user, and clicking on a button on the hud will play an animation. When I press the button, the animation is correctly played:

MyAvatar.overrideAnimation(animationURL, 30, false, 0, 45);
Script.setTimeout(function () {
    MyAvatar.restoreAnimation();
}, 1500);

I read that the prefetchAnimation call can be used to cache the animation before it’s used, so I then added a call to it with the same url in the setup code for my script. When the script gets there, it terminates:

function setUp() {
    print("Running setup");
    ...
    createOverlays();
    Controller.mousePressEvent.connect(onMousePressEvent);
    print("before");
    MyAvatar.prefetchAnimation(animationURL);
    print("before");
}

When this runs, the console will print “before”, then nothing. Opening the log from Developer -> Log, I see these lines:

[07/13 14:19:52] [DEBUG] Logging activity "loaded_script"
[07/13 14:19:52] [DEBUG] script:print()<< Running setup
[07/13 14:19:52] [DEBUG] script:print()<< before
[07/13 14:19:52] [WARNING] [UncaughtException] TypeError: Result of expression 'MyAvatar.prefetchAnimation' [undefined] is not a function. in file:///path/to/myscript.js:193
[07/13 14:19:52] [WARNING] [Backtrace]
[07/13 14:19:52] [WARNING]     setUp() at file:///path/to/myscript.js:193
[07/13 14:19:52] [WARNING]     <anonymous>() at file:///path/to/myscript.js:201
[07/13 14:19:52] [WARNING]     <global>() at file:///path/to/myscript.js:204

EDIT: I’m running Sandbox and Interface build 5111 on a MacBook Pro with 10.11.5.


#2

I think maybe MyAvatar.prefetchAnimation() was deprecated a while back – this might work instead:

var _animation;
function setUp() {
    print("Running setup");
    ...
    _animation = AnimationCache.prefetch(animationURL);
    ...
}

#3

Thanks! That seems to fix it. I suggested an edit to fix the documentation.