Tween in a function

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?

You are doing something wrong, but I can’t tell you what without knowing what you do. :wink:

image
image
image

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:

To call the function, I just did this:

tween-broken2

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.

I’ll have to look back at my game and run it in the debugger to see if I can get more clues as to what is going wrong.

1 Like

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.

My function is defined like this:

I used it like this:

The Tween does nothing.

If, however, I move the code out of the function and into the scene, it works fine:

So am I doing something wrong, or is Tween unreliable when used within a function?

i did the same thing, you did, and it works.



Make sure, the Z order of your created flash is greater then the ToExplodeObject.
maybe its hidden behind something, or on the wrong layer.

It won’t be the Z Order. The Flash object appears immediately and stays steady on-screen. It does not fade in nor out.

The events work
Seems like you have to upload your file.
The only way to find out what’s not
working for you.

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 challenge is: why does the function not work?

The resources are:

  • game.json
  • BlueSquare.png
  • Flash.png

and can be downloaded from:

i have fiddled around with it, and tbh, i actually dont know, whats broken exactly.
but i did mange to fix it, but how? dunno.
Fixed File

maybe ill investigate this later.

Both tween identifiers have to be the same I think.

Downloaded your Fixed File, but it didn’t work for me. It just create the white circle. No tween.
This works for me:

BTW: I don’t know why the Flash is not created in the center of BlueSquare, but at its bottom right.

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.

How do we officially report this bug?

It inst really a bug, since the parameter name needs to match the object. And tween is a fixed name.

So the only thing is, that tween behaviours cannot be renamed, so it should ether ignore the naming or be fixed set to Tween.

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?

i would assume thats true for all behaviors

And why it’s not being created in the center of BlueSquare?

Because both box and circle do not have ther origin in the center