Cursor sprite lag

Greetings,

I got a problem in my relatively complex project I’m working on, so sharing the events or the file itself wouldn’t help much as there’s a lot, so instead I’ll ask a general question.

What could be the reason behind a sprite cursor lagging behind briefly when left-clicked? It is set up that every time I press the left mouse button, a few objects get created for a second or two. I thought it must be something with performance and how it’s optimised, but when I checked the performance tab during the time it lagged it showed 1.26ms under “All”, which should indicate great optimisation, right?
Everything else in the game still runs smoothly, I set up rotating objects around the scene, but not one lagged once. Only the cursor sprite object has the problem.

So I’m confused as to what the problem could be. I switched from the “Cursor object” extension to manually updating the sprite’s location to the cursor, thinking the extension might have a bug or something, but no, the problem still persists.

I would appreciate any help.
Thanks in advance.

It could well be the way you’ve structured the events. Could you post screen snips of events that deal with the cursor?

1 Like

I actually found the event that’s creating the lag, but I still have no idea why. Take a look:

It has absolutely nothing to do with the cursor except that the cursor creates the Visualizer object when the left click is pressed. The Visualizer is an object that goes through the scene and creates Path_Visualizers (small circles) and gets deleted after a bit.

Here is the performance profiler during the frames when the event above was turned off:

And here is the performance profiler during the frames when the event above was active:

These amounts like 0.68ms shouldn’t create any problems for me…
Would you know what I could try to do? (besides not using the event, it’s crucial for the game)

Code on the cursor please.

1 Like

Am I correct in understanding it’s creating a visualiser object, that then creates a series of other objects, and all are being sent over the network to other players?

Can you screen shot the code where the visualiser creates the other small circles?

1 Like

Regarding your second question, there are no other small circles. The event I showed above is the only one that spawns these small circles (Path_Visualizers).

Regarding your first question, yes, that is what happens. I left-click, a Visualizer is created, it moves with forces across the scene and every 0.05 seconds it creates Path_Visualizers that stay to exist.

But more importantly, I got closer to finding out the problem. It’s the multiplayer behaviour for the small circles (Path_Visualizers). When I delete it from the object, the cursor ceases to lag. Thinking logically, it might be that the game instance that’s creating those objects and sending all that objects’ info is overwhelmed with all the data it has to send, and I guess the consequences of that affect the cursor specifically. Not sure what else to conclude here.

I’ll send screenshots if you need anything else later.

That’s what I was angling towards. What about ,instead of creating and deleting them, you kept them in the scene and instead hid the visualiser rather than deleting them and showing the visualiser in place of creating it?

1 Like

I see what you’re saying, but the Visualizer isn’t the root of the problem, the Path_Visualizers are. I tested this a bit, I had 100 of Path_Visualizers at the start of the scene and I changed the location of one - the cursor lagged. There’s no way it’s lagging because of sharing the data of only one Path_Visualizer, so my theory is that GDevelop checks and sends info from every single one, even if only one is changed.
If that is indeed true, then I’ll have to rework the system.
Now that I’m thinking about it, I should have never went with having so many objects/instances that use the Multiplayer Behaviour in the same scene, so this whole problem I’m facing is completely on me…

I think I might know why the cursor specifically is lagging - it’s because it has the Multiplayer Behaviour as well, and what might happen when I left click is that until then the cursor spite’s location was being sent normally, but gets interrupted by GDevelop having to check all the Path_Visualizers first for whatever reason, which renders the cursor sprite unable to be processed until it gets its turn. It’s a wild theory, but I think I’m on the right track. I’ll test it more and see what I come up with.

All in all, so many objects/instances with the Multiplayer Behaviour was a bad idea.

Did you first even try using the “Trigger Once” In the event’s condition?

That’s pointless. The condition is a timer, and it gets reset in the actions. The next time the event is processed the timer less than the threshold and will no longer kick off the action, so a trigger once is redundant.