Actor unloadAnims() not working?

I want to remove an animation from memory. This doesnt work, animation is still playing.

from panda3d.core import *
import direct.directbase.DirectStart
from direct.actor.Actor import Actor

panda = Actor('panda')
panda.reparentTo(render)

panda.loadAnims({'anim': 'panda-walk'})
panda.loop('anim')

#panda.stop('anim') # not like this would change anything
panda.unloadAnims({'anim' 'panda-walk'})

run()
>>> 'anim' 'panda-walk'
'animpanda-walk'

rdb is pointing out a basic syntax error in your code.

The correct way to unload anims from memory is to first make sure the anims in question are stopped, and then call unloadAnims with just the list of anim names (not the anim files):

panda.stop('anim') # this is important
panda.unloadAnims(anims = ['anim'])

Or if you want to unload all of them, you don’t need to specify anything (but you do still need to stop them):

panda.stop()
panda.unloadAnims()

Of course, if you really want to completely expunge the animation from memory, you also have to clear it from the ModelPool.

Usually, there’s not any reason to actually unload an animation from memory, though, unless you are really tight on memory consumption; and unless you know what you are doing and are careful to unload all references to an animation file when you do this, attempting to unload the animation might actually waste more memory because it breaks any shared references, and will force the animation file to be reloaded again from disk the next time you load the same file. So if you didn’t completely unload it, and then you load the same file again, you end up with two copies in memory instead of one.

David

My mistake. However the dictionary argument for loadAnims is not only my mistake:

panda3d.org/manual/index.php … Animations

Tuple?

Hm…

from panda3d.core import *
import direct.directbase.DirectStart
from direct.actor.Actor import Actor

panda = Actor('panda')
panda.reparentTo(render)

panda.loadAnims({'anim': 'panda-walk'})
panda.loop('anim')

panda.stop('anim') # this is important
panda.unloadAnims(anims = ['anim'])

run() 
Assertion failed: _pointer != (const CycleDataType *)NULL at line 106 of c:\buil
dslave\dev_sdk_win32\build\panda3d\built\include\cycleDataLockedReader.I
Traceback (most recent call last):
  File "tets.py", line 12, in <module>
    panda.unloadAnims(anims = ['anim'])
  File "C:\Panda3D-1.8.0\direct\actor\Actor.py", line 2263, in unloadAnims
    animDef.animControl.getPart().clearControlEffects()
AssertionError: _pointer != (const CycleDataType *)NULL at line 106 of c:\builds
lave\dev_sdk_win32\build\panda3d\built\include\cycleDataLockedReader.I

Ah, sorry, that looks like a minor bug in 1.8. I’ve just committed a fix.

David

What about the manual code? Is that right?

It’s mostly right, technically, except for the use of the word “tuple” instead of “dictionary”. You can, indeed, pass the dictionary that you used to create the Actor in the first place. But that’s not really the intended usage; I don’t know why you would even want to do it that way.

I actually edited the manual and took this bit out altogether, because it’s distracting information for new Panda users. There’s really no reason for a new Panda user to know about unloading animations, because that’s a fairly advanced topic that you wouldn’t need to do (and shouldn’t do) until you actually need it, which is really pretty unlikely unless you’re already knee-deep in pretty advanced techniques. In that case, the advanced user will know what he needs to do, and will go looking for the interface and presumably be able to find it.

David