Have a less impactful way for performance when synchronize frames between different sprites

Hello! :v:

I was trying to solve a problem in my game when it cames in my mind that could be a good feature request. My Character can attack while he is walking because there is different sprites to his hand/weapon and the body. But after the attack animation over I need the hand/weapon come back to the same animation and frame of the body. It’s possible to make, but it won’t stay in sync, because part of the time of that frame in body is already passed and the hand will start the same frame from the beginning.

Example with 2 objects that have the same animation “Numbers” and one will make the “attack”:

Result:
Gif

The only way that I know how to fix this is set an event that constant check if the frames are sinc:

And the problem is that this solution is not very good for game performance. I probably won’t have any issues with my game because it’s just a single sprite, but games with multiple sprites that need to be in sync may have issues. If there’s a better way to solve the problem that I don’t know about, I’ll be happy if someone teaches me!

I’ve been thinking… Could another expression that returns both the frame and the time used in that frame be a solution?

Thanks!

Since you have groups you could apply same action to whole group
Only thing you would need to care about is to set same names for animations or use same numbers of animations for said sprites in that group

Maybe the title didn’t make my point clear. Sorry. I believe that even using group it will be necessary for Gdevelop to check every object within it in every frame. Which means that the more objects within that group the worse for performance, right? That was the point I wanted to raise. I’m going to change the title.

But that is obvious fact
It is same like you ask does moving with force to the left 1 enemy is better for performance than moving 100 enemies to the left with force

I doubt there is any solution to that

I believe that with an expression (or maybe another solution) we could use it in conditions that allow it to be changed in only one frame, instead of having the need to check constantly.

Edit to better explain.: as soon as you sync your animations between different objects and the animations have the same speed and frames, you don’t need to sync that anymore. That is why your comparison with forces is not compatible. Forces need to be applied to each frame.

Maybe it’s me. I need an example.

Is it like having 2 walking animations. One is wearing shoes and one isn’t. So, you want to sync it. IDK. That would be easy. Save the current frame number, change the animation, set the frame to the saved frame number.

Or is it like having 2 sprites in motion. Say spinning gears. You want to bring them together while each is spinning but you need to sync them while they’re both spinning. So, the gear teeth align.

That would be tougher. You would have to either slightly speed one animation up or slow it down until they synced together. And then you would set them to the same speed.

I’m assuming there’s already a formula for that. Maybe lerp or something.

IMO, you can work hard to sync things perfectly but because it’s so small and happens so fast that the player probably wouldn’t even notice.

Nah you did not get it
I mean performing same action on multiple objects will be performance heavy
It have nothing to do with syncing
You assume i meant syncing constantly but my idea here is that animation of all sprites is changing constantly
That’s why force example apply here also

You see on 2 sprites i would not see a problem on 200 i would start to see a problem
Not because of 200 objects but because of all your crap running in background in your game and 200 objects changing animation constantly at the same time
That could be felt in your game performance if you would have much going on in it
Since animation change alone would handle over 1k of objects without problem
But why to change 1k objects animations?
You would move them? Maybe walking units and that is already FPS drop
So bottom line is how many objects are we talking about and for how heavy game
My best idea to not sync all animations of all objects is to just perform same action for these objects
Instead of trying to sync all objects to one object
This is all just speculation but in my eyes that would be most logical solution

It’s a fine line. I’m assuming it’s just 2 sets of animations. If you sync up too much, you lose the randomness and everyone would be walking in formation. I’m guessing it’s only to get things like arms or guns in sync with the body or something.

@Keith_1357

But I gave you an example :eyes:. And the example in my comment shows, just placing the frame according to the frame of another object will not cause them to be synchronized.

It won’t bring the ideal effect, but it can be a solution for some people on certain occasions.

I think it depends on the situation and speed of the animation. Although my sprite is small, 64x64, the movement of the arm with the weapon desynchronized is very evident and weird.

@ZeroX4

I assumed you were talking about synchronization because I was talking about synchronization :thinking:. Anyway, lets move on

That’s why I said I probably don’t have issues with this, but people with multiple sprites syncing every frame maybe have impact on performance. So, that’s why I come with the feature request.

I think this is not a good solution. I’d rather have a new expression to avoid the impact on performance and be much more practical than limiting the build of the game.

I think you have a good point. Maybe only in more extreme cases it can be a real problem. Maybe I shouldn’t have tried to anticipate a possible problem that I don’t know if it’s a real problem since I don’t experience it in my game. But since I want my game to be mobile, I try to keep it as performant as I can. Maybe I overdid it a little bit this time… :eyes:

1 Like

@Keith_1357 Evidence 1
I would wish this idiots would sync walking animation
Yeah that would strip them of randomness and natural feel
But sole option to do so would be cool for various of situations
2023-10-26_09_37_l5R6GGMcRs_GDevelop
Imagine instead of “humans” i would have there robots
And for purpose of whatever game i would be making syncing their animation to act as a “hive” would be cool

@Rasterisko Evidence 2
I am making auto tile extension
And it works problem is i need to update ALL tiles on scene (not screen but whole map)
At once
Or i can update only ones you see on screen then update again ones on screen if you move
Both solutions presents FPS lag
2022-11-11_09_36_YM7Rq1wyjL_GDevelop
The more tiles i have on scene the more FPS drops when i create/destroy (hence update) tiles
I found a way to update only ones that are adjacent to one created or destroyed but it is not so simple i need to change variables of tiles not 1 tile away from center tiles but for 1 and 2 tiles away in each direction from center tile when i create or destroy tile
Then i need to update only ones that are 1 tiles away from center one
Or i end up with this


it is not accurate example but you see the problem that some tiles are not properly connecting to others

And if i would only update variables of 1 tile away from center one and then update them than they would only connect to each other but not beyond that area

That why i need to change variables (to which i write from which side other tiles are touching center tile) of all tiles that are in red area
But update only ones that are in blue square

I know exactly how to do that and hopefully extension will be FPS lag free
BUUUUT not so much
You see problem is that when i start the game i will still need to update ALL tiles at once
And if you really wanna see how changing animation of 342 objects at once (in upper left you have current number of tiles on scene/map) lags
And that is not that much of tiles anyway


It is that much tiles
Now imagine if i would have actual whole map filled with them
Where i will need to add water farmland dirt sand and few other tiles
That number would go way higher
Right now it would be like idk 1 sec lag
At 1k tile that would be like 5 sec lag and it need to happen for all tiles after starting game to have proper animation (properly connect to other tiles)

And i really can’t see any solution for that
And that is only updating frames ONCE (i change frames on 1 single animation instead of having animation for each tile image)

Now imagine syncing animation of 100 objects but changing constantly their animation
That would be cool underwater/moon speed effect
Slug mode unlocked

Now do you see real problem?

It is not about expression extension or a way to SYNC multiple objects at once
It is about doing something to multiple objects constantly
That is the issue and actual performance drain

Still not convinced?

Launch it on your phone and shoot some UFO’s

UFO’s move with forces
While coins move with physics
It is not that much on screen
It is how much on screen is affected by something AT ONCE

Unless you have powerful phone you will feel the struggle FPS is having

1 Like

If you read my first comment, you’ll notice that this is exactly what I’m trying to avoid by proposing some solution to be able to synchronize the frames of objects sprites without needing an event that does this constantly. So, to be honest, I didn’t understand what your point was in that last comment.

And just because my feature request isn’t a solution to your game’s performance issues, doesn’t mean it can’t be for other developers, knowing that games are built in different ways.

Rast
You still don’t get it
I do not mean my game the hell with it
I do not mean WHAT type of action

I say problem is in TO HOW MANY objects
And that is something you can’t bypass

Maybe I didn’t get your point or you didn’t get mine. Sometimes people don’t understand each other, but that’s okay, right? :wink:

As I said before, I probably shouldn’t have made a thread if I’m not experiencing the problem. I was too quick to find strange that I didn’t have a way to sync frames without needing an event that does it constantly. But thanks for your explanations, ZeroX4!

So this thread has gone into some odd tangents. Just to bring it back around I wanted to add some context:

Short answer:

  • Any logic that impacts all objects will have a performance impact.
    • It doesn’t matter if you’re manually setting an event that syncs the animation frame (As your screenshots show in the OP) or it’s some sort of backend behavior that is syncing them. The impact is the same, there is no reduction of overhead.

More context:
Keep in mind that performance is not the same as order of operations. Even though you’re seeing some delays on your syncing (which I don’t have time to debug in more detail currently), that’s not a performance issue, that’s just an order of events item. You could potentially more evenly synchronize the order of operations by having a function or behavior that syncs their animations pre-event sheet with a lifecycle function, if you want.

Where you can get improvements is in your object selection. If you’re going to have multiple types of objects. A lot of people use “For each” when they really should be using the “Pick all” condition on a single event (Or no condition at all and just have it apply conditions as normal). For each will always be more performance heavy than the other scenarios, all other things being equal.

Da fak
We come here to get clarification on something or learn something
So that is exact what we are doing here

Look bottom line to my understanding and by computer logic
If you perform one action on one instance it is ok
If you perform same action on multiple instances then it will need more processing power and there is no way around it

Imagine thins like you have notepad ++
You can ctrl+f to enable find window
You can then go to find and replace tab and like search for word you want to replace with another word
IF you have like 3 instances of that word it is ok
BUT if you have 3000 instances of that word
Even so text replacing is not so resource demanding process it will cumulate and you can feel like 1 sec lag before action is complete
And same logic goes to everything in computer performance world

But what i wrote above is just covering one aspect of our conversation
Explaining performance issue

I am fully aware you are here to ask for method to just sync something to all instances of something
And not be forced to manually set same action for multiple instances

We just get little side tracked here and nothing wrong in that

This looks interesting…
i wonder why in my game (that use a 4k resolution, each conditions ecc…) i’ve no lag…probably due to my rig spec? i dunno…
btw imho in the OP something in the screenshot is wrong, since you want actually to get the same number at the same frame…BUT:
you want an ACTION to happen at the same “time” of a CONDITION and it’s something that you can’t achieve in any known language or even with 1000 cores cpu. Since even for nanoseconds CPU must elaborate your input. (that we call “LAG”)…(probably AI gonna change that…i dunno)
So the solution is what you already answered here:
“The only way that I know how to fix this is set an event that constant check if the frames are sinc”
and thaz heavier

@Silver-Streak, Hello, Silver! I haven’t seen you in a while! :v:

I only see delays in my synchronization if I try to sync it with conditions that make the event works only in one frame, like this:

In this event Red object will change animation to “Numbers” (the same animation as Black object is already playing in scene) and the same frame as Black, but since Black is already playing, part of the time of that frame for him has already been passed. So, with this event I can’t synchronize perfectly (in fact, it would even succeed on very rare occasions when the black object would have started its frame at the same moment).

So the simplest way that I know how to solve this is to have an event that performs synchronization constantly. And with this event I didn’t see any problems with the synchronization:

And now the main point of this topic: can this be a problem for performance if someone is using a lot of objects that need to synchronize some animations? For example, enemies with 2 or 3 separate sprites that eventually change the animation to attack, damage, or something and resync with the animations of other sprites? If so, I think it might be a good idea to have a simple solution to it (maybe with an expression or extension like @Keith_1357 says) and be able to synchronize animations with events that only work one frame.

@Keith_1357 and @ZeroX4 gave some good workarounds, but that’s it: workarounds. Again, for now I don’t know if there is a simple way to solve this.

No, that’s not my point. To synchronize multiple instances, we can use the groups as you said before. Look my explanation for Silver and see my point.

@RMDB

I don’t know if I get :thinking:. Here’s an example of what I was imagining might be the solution:

We know that “FrameSync()” didn’t exist as an expression, but if it did, I’d expect that in addition to placing the same frame, it would also take into account the time that was spent on the object to be perfectly synchronized. But I liked the @Keith_1357 idea of having an extension for this instead of an expression. I think that would be a much better solution than this very strange and specific expression.

1 Like

Referring to my previous answer…
The problem is that you’re telling to GD what happen when a condition Happen.
You’re not telling him that both results must be in Sync.

@Rasterisko I was hoping my explanation of what you come here for was exact that

Fak
That is issue with me i try to explain fully what i mean and in the process when explaining multiple things i miss out some context and it seams like i meant something else

But problem here is that you ask for expression on extension because you are concern about performance

So let me repeat what me and others here told you already
Problem is not in how you gonna perform it upon multiple objects
Problem is on on how many objects you gonna perform it

It is not like there is difference will it be cascade effect or single strike
It is more like on how many objects it needs to be repeated which with each object means more processing power needed

Look on one hand it would be cool to have expression like Object.CenterXY()

Instead of you need to specify Object.CenterX() and Object.CenterY()

But that is just cutting how much you need to type
And not improving performance

Again all comes down to on how many objects you would use it