I passed a Sprite object with a Tween behavior as a parameter to a function and also configured the next parameter for the function as “Behavior (for the previous object)”. I get the Tween options appearing for the sprite, so I can use them in actions, but they don’t work when the game runs. The Tween does nothing.
If I copy the actions out of the function and put them as events in the level directly instead, the Tween works fine.
Am I doing something wrong, or is it simply not possible to use Tween inside a function?
I am doing something wrong? I’d love to know what I’m doing wrong.
With further experimenting in an empty project, it seems the tween in the function does not work if you also try to create the object that you wish to tween. For example, this is not working for me:
However, if I delete the ‘Create object’ action and drag the object that I pass to the function into the editor window so that it is there from the beginning, the tween works.
So, perhaps I should modify my question: how do I create an instance of an object and tween it inside a function?
Ah, actually, I just noticed my test case is a bad one, because it creates objects forever. If I put a sensible condition around it, my test case works fine, e.g.
Ok, this is definitely not working and I cannot explain why not. I’ve pared the problem right down to almost what I tried on the empty project above, and cannot get the Tween to work when it is in a function.
I started with an object called TestSprite that is a blue rectangle and a second object called Flash that is a white circle with one behaviour configured for it: Tween.
Here is the reproducer. When I open it in GDevelop (I’m on 5.0.0-beta105 on Windows 10) and play the game, I hover my mouse over the blue square, and a white circle appears and stays constant on screen.
Then if I change the scene events by disabling the top event (which calls the Explode function) and enabling the bottom event (which does exactly the same as the Explode function but directly in the scene instead) and play the game again, now when I hover my mouse over the blue square, the white circle fades in & out as expected.
The first fixed file by Slash didn’t work for me either.
The second fixed file by zutty did.
Then I tried something else, I went back to my original example, and renamed Parameter #3 from ‘FlashTween’ to ‘Tween’. Then it worked!
So something a bit buggy in GDevelop at the moment, whereby the parameter name isn’t arbitrary and some things won’t work unless you type in exactly the right name for your parameter. Weird huh?!
Yes, that was my suspicion too, that the parameter needs to be the name of the behaviour.
It worked, after I changed it to tween.
But to confirm it, I renamed it back to your naming, and it still worked.
Seems it only did for me tho. Maybe it won’t work after a restart.
Right, that’s what I mean. So is there an official way to log this issue so that it might be improved in a future release? Does it only affect Tweens, or is this going to hold true for all behaviours?