setSequence doesn't change animation

Hey,

I’m trying to change animation in existing object.

I’m creating object:

local objProps = { name = "cat" .. counter, x = 100, y = 100, assetName = "cat", xScale = 0.13, yScale = 0.13, followPathProps = {path = 'path\_18, direction = 1, rotate = false, rebound = true, repeats = -1, delay = 2, autoStart = true, xFlip = true, yFlip = false}, } local obj = myLevel:createObject("animals", objProps) obj.view.speed = math.random(1,4) obj.view:setSequence( "catWalk") obj.view:play() local path = myLevel:getLayerObject("animals", objProps.followPathProps.path) obj:followPath( path, objProps.followPathProps) animalsTable[1] = obj

then I get this object from the table and try to change sequence:

local obj = animalsTable[1] print("obj.assetName = " .. obj.assetName .. obj.view..sequence: " .. obj.view.sequence) -- output: obj.assetName = cat, obj.view..sequence: catWalk obj.name = "monster" .. counter obj.assetName = "monster" counter = counter + 1 obj.view:pause() -- I can stop the animation obj.view:setSequence( "monsterFly") obj.view:play() print("obj.assetName = " .. obj.assetName .. ", obj.view..sequence: " .. obj.view.sequence) -- output: obj.assetName = monster, obj.view..sequence: catWalk

I called obj.view:setSequence( “monsterFly”) but it doesnt change the sequence. There is still old value.

You seem to be getting confused with your objects as you have only created an object of asset type ‘cat’.

The key part here is ‘CreateObject’, which based on the asset name applies the animation sequences.

In your code you get the cat object from your table and then change the asset name to ‘monster’ which does nothing more than change the asset name, it has not created an object of type ‘monster’, so all the animation sequences applied to this obj are still from cat.

You can’t really change an existing object you have to create a new one.

It is possible to have three objects e.g. obj, cat and monster and then set obj to either cat or monster when needed.

ohhh ok. So I can’t change Sequence to another from different asset, I can only choose other sequence but from the same asset in  animation table right?  That’s logic. Thanks

That’s right, each asset only knows about its own sequences, you need to create an instance of a different asset to access its sequences.

You seem to be getting confused with your objects as you have only created an object of asset type ‘cat’.

The key part here is ‘CreateObject’, which based on the asset name applies the animation sequences.

In your code you get the cat object from your table and then change the asset name to ‘monster’ which does nothing more than change the asset name, it has not created an object of type ‘monster’, so all the animation sequences applied to this obj are still from cat.

You can’t really change an existing object you have to create a new one.

It is possible to have three objects e.g. obj, cat and monster and then set obj to either cat or monster when needed.

ohhh ok. So I can’t change Sequence to another from different asset, I can only choose other sequence but from the same asset in  animation table right?  That’s logic. Thanks

That’s right, each asset only knows about its own sequences, you need to create an instance of a different asset to access its sequences.