[SOLVED] Is it possible to check if two objects in collision have different variables but specific ones not just not matching?

Look at this picture


We only care about green and red square but each square is same object
Let’s just call this object square
Now each of them have number variable
As you see green have 1 while red have 2
And all squares are in collision with themselves

Now let’s say i wanna check if square in collision with green square have variable equal to 2
But the problem is at the same time i need/want to check if green square have variable 1
So for both of them i can set variable to 4
Not affecting or simply ignoring other squares with variable 3

Is it possible in gdevelop?

How are you deciding which 2 to check? Which is red? Which is green? Is the border always going to be 3 or the same number? Is it aways going to be the same shape? I think we need some more context.

I just finished writing this reply and damn it is wall of text
But i think it answers any possible question and explain what i want to achieve how and why
While it shows at what state i am right now

It’s for AutoTile extension so my options are limited
I can’t create another (different) object or use another sprite animation
I have only 1 object with 1 animation (which have multiple frames) to use
It is always same size and shape (perfect square)
But size can be different like i have 16x16 pixel object
While someone can make 8x8 sized object but all objects that will be colliding will have same exact size since they are copies of same object (Tile) so i doubt that is something to consider

I have all the logic to find from which side (top-left, top, top-right, left, center, right, bottom-left, bottom, bottom-right) other objects are colliding
Checking for diagonals is made with bounding box and point inside object
For top down left right ones with comparing two numbers

Problem is when object is placed it gets variable with value 0
After check of any possible adjacent neighbors i change their value to 1
Then after they get proper sprite animation frame value is changed to 2
(i have 1 animation with many different frames and i set different frame depending on adjacent neighbors instead of adding each image as separate animation which would be time devouring)

So imagine we are on the grid which have same size per cell as object
Now where you see green square i gonna place new object (Tile)
And it’s variable will be equal to 0
image

While all red ones have variable equal to 2
Now i wanna change only red ones variable to whatever other value that are adjacent to green one but do not affect any other red tiles that are not adjacent to green one
That’s why i need to check if tile with variable 0 is in collision with tile with variable 2
I can’t check only one variable since that will give me nothing
Since either i will only check green tile or i will check ALL red tiles

I came up with the idea (with help of @Reborn ) to make that green tile width and height +2 and then change it position to its own position X-1 Y-1 (Object.X()-1 same for Y)
This way it overlaps all adjacent tiles and collides with them while i check for collision with this option in collision condition set to yes
image

And since that object is created and i have function in extension to use lifecycle method of when object is created it works like a condition
So it only changes width height and position of newly created tile
And so with that option from screenshot above it affects that newly created tile and ones that are in collision with overlapping tile
Since collision check condition is not satisfied if only edges are touching
Then after i give them all unique value of that variable all tiles in collision with overlapping one+that newly created overlapping one have their variable changed to 2 same like any other tile
And i change back width and height of that newly created tile back to -2 and position back to X+1 Y+1
So it looks seamlessly

So i have workaround for now

I made post with this question before i found solution to my problem
But i am using collision check which is resource heavy and works of a timer/wait action

So even so i have it working i am forced to limit checks per time frame
And if something in game lags/freezes tiles may not update properly
So if there is way to check what i was asking for in OP that would reduce possible problems and reduce eventual lags

Here is how it works for now (link at end of this wall of text)
That tinting of tiles is made on purpose so i can see how far updating goes per tile to test under different FPS lag

Updating after destroying tiles is not yet created but i would simply spawn new tile in place of destroyed one and repeat whole process from above then simply delete that newly created one

If you walk around while holding LMB to create new tiles you can already see it is lagging because check happens on each frame multiple times
Also more tiles newly created tile is touching more laggy it gets
But i can diminish it by reducing time for how long check is going to last

Other buggy thing is hold LMB and just move it like crazy on grass to spawn many tiles fast and some of them won’t update properly

If i simply could check if 2 objects next to each other have variable 0 and 2
And only affect them then it would remove any lags at all
Since update of a tile would happen until both objects are updated and their variable is changed and not based of a timer which as you see affect more than it should
Since i use variable value as condition and it does not lag running every single frame

That check for object with value of variable 0 in is next to object with value of variable 2
Would remove any possible lag at least i hope so

I thought that’s what it might be for. I remember it from your adjacent tile problem. Have you tried using point is inside? If I remember correctly, you used the behavior object against the other tiles.

If object variable = 0 then check points on each side using + and - a few pixels from the bounding box. If point is inside then do what you need to do. You can limit the checks by picking only objects whose variable=2 before the point is inside.

If you’re doing this as a separate function with just the one object name then if the object isn’t already picked, you could select the object(s) with variable=0 and save the points to an array of x,y structures. Then pick the objects with variable=2 and see if the points are inside of them. You could use a for each child of the points variable within a for each object of the objects with variable=2.

I’m not at my pc. I’d like to play around with the concept.

If you’re doing this as a separate function, this works. It’s straight forward. Pick the objects with a value of 1, add the locations 10 pixels away from each side to an array along with the location of the currently picked object. I was going to use an ID but using the location removes the need for a counter. The other half of the code goes through the array of points and checks if there’s an object there with the value of 2. If so, it turns on the outline effect for both objects.

The objects are draggable. Click the button to test it. It draws a circle at the test location and turns on an outline effect.

I created a little function to add the points x,y and the location of the object being used as the reference object to an array. It was easier than repeating the events for each side.

The function is named “Add Point To Array” and uses 3 parameters X, Y and Obj (number, number, object)

These are the main events. It uses a sprite named “Box”, it’s just a white square, a shape painter for visuals and a button.

I again made huge wall of text because i found other solution did not even try yours
Basically IsOnScreen extension and i used that which was giving A LOT better performance
But as soon as i zoom out (since it updates only visible objects) it started updating more of them and lag came back

Then i realized i am approaching it the wrong way i am trying to limit how far from created tile in grid spaces update will happen
When i was ignoring i am still setting variables for ALL tiles on scene (not on visible screen viewport)
So all i need to do is for setting variables happen on visible screen section
And then update newly created tile
Do it either by limiting it with is on screen extension
Or setting somehow setting variables to happen only for adjacent neighbors of newly created object

One problem i have is on destroying tile i am unable to place another tile in it’s position since it does not exist anymore so no position to check/use

If you would have any idea how to solve that (create another tile in place of destroyed tile)
Or affect somehow adjacent tiles of destroyed tile that would be awesome help

Also can you upload your project and paste link to it here?
I am new to extensions i understand maybe like 80% of what i see on your screenshots

Anyway your method looks like a solution since collision checking alone seems performance heavy but again i can limit it by is on screen extension
But then again if someone will zoom out then is on screen extension will again include all visible tiles on screen which means lag again

I will have a lot of testing to do today since it is already almost 5 am

So far BIG THX for your help

Anyway here is version limiting updating and setting variables of tiles with is on screen extension

Feel that smooth action on default zoom

But then try to zoom out and then spam LMB

Before you delete the tile, store it’s x,y in a variable. Maybe set a Boolean so the other part knows it needs to do something. If there are several objects, you could add them into an array as a buffer. IDK.

I can add my example to GitHub. I’ll update this post when I do. I’ll also check out your current online version.

Update: Here’s my project. I created the extension because it allowed me to add the values to an array with a nice, single line action instead of adding 4 lines for each point. It’s a fairly easy setup.

Note: this is barebones to make it easy to understand. You might need some checks and balances so events only happen when there’s data or applicable objects.

Edit #2: I checked out your version and there is serious lag. Maybe if the objects have an updated Boolean. IDK. You only need to run the update when the stones are added or destroyed.

I had lag when you shared your earlier version. For me, it was because of all the grass objects. I replaced the grass with 1 giant object and the lag went away, The grass is made up of 1,500 tiles.

How am i supposed to store data of object before destruction if i can’t do anything to it on destruction?
Or do you mean like store all stones X and Y position then check which is missing?

And grass in my project is just a background color not even an object
And yeah before it was 1 object per grid space

OK so now Keith i need to give you apologie
Because i wasted your time for no reason
This is 4th time when it turns out i had all the answers and knowledge to do stuff myself i just was not smart enough to put 2 and 2 together

So basically this is how horizontal and vertical tiles are detect and given variable


It is 1st checking if objects are in collision then compare their center points position

(just a side note i did not try this but correct me if im wrong
I could go
Object.CenterX() = Tile.CenterY()
Tile.CenterX() > Object.CenterX() to check if there is something on the right
BUT
Object.CenterX() = Tile.CenterY()
Tile.CenterX() > Object.CenterY() - Object.Width()
And now im checking for Top Right diagonal neighbor
Since width of tiles are the same for all of them so width of object = going to same spot in next grid cell in this case -Y is going UP and width of object would mean it goes to its center point
Damn i feel stupid)

And this is how diagonal objects are detected


It simply check point inside object based on some distance from bounding box side

That bounding box check seems less performance heavy and i could use (and actually did) that to check for anything anywhere like instead
Object.BoundingBoxLeft() -5 Object.BoundingBoxTop() -5
To
Object.BoundingBoxCenter() Object.BoundingBoxTop() -5
And this would check if object is above instead of diagonally top left

So again i am sorry for wasting your time just because i was not clever enough to stress my brain enough to figure it out

Anyway Tile vs Object
Object = when it is created and nothing is done to it
Tile = Object after it is set to Tile (which means behavior on this object is activated and it is given variables and based on them it get proper animation frame set)

So even so i have 1 object in reality i can kinda check for two Tile and Object so i can go


To check if there is any Tile above and Object below will be affect

But then i can do this


This do the same as above event but instead of doing something to object below it do something to Tile above
I know it sound confusing but imagine it like this
Steak you buy in shop and steak you buy in restaurant are both meat
But only one is raw

This way i have ability to check for adjacent tiles of newly created object and do something to that newly created object and adjacent tiles
So in other words i can manipulate animation frame of center object and all other 8 adjacent objects

Works perfectly until i found what is causing FPS drop

Well 1st of all more tiles i have in scene more FPS drops and game become performance heavy
I found that less behaviors i put on object then less performance heavy it gets
Then i found out that even if i have just 1 behavior (any behavior from extension) on object it will start dropping FPS if i spam too much tiles on screen
And then i found out that even if i disable all events in extension and i de-activate that behavior via events in event sheet
It will get better but still will produce FPS drops if too much tiles are on scene
It is ok for idk around 500 objects i did not count exactly
But imagine building map out of tiles
You will exceed that numbers especially for stones trees farms potential fence water and stuff
No to mention ppl would use that extension mostly for level editors/builders i guess
So state of it is sad
If i am to finish it i will need to warn ppl to zoom in a lot and don’t spam left and right tiles like crazy or they get lag

But what i do notice if i ditch extension and do it via events (whole auto tile thing)
I get way smother experience and i can spam a lot more tiles before any FPS drop
But that is a lot of work for each tile type i would want to set
Probably i could streamline the process but whatever

Anyway i care to share with you what i have done so you can play with it
Maybe you will find some solution or maybe just use it for fun if you find it interesting

Only Stone and Water have that behavior and proper frames so won’t work on any other object

There are 3 modes for Auto Tile updating
Which you can switch when you edit extension
Names should be obvious enough
Just enable one at a time and disable others

Green
is the one with collision check the one with which i started
Lags on destroying tile since it checks all of them
And little lags on creating tiles if there are too many

Red
Have better performance but also lag on destroying tiles
But lets you spam a lot more tiles before FPS drop

Blue (which is copy of Red is using Is On Screen extension)
Best performance of them all
Updating on creation and destruction of tiles you see on screen
It also updates each time camera moves 10 pixels in any direction

But it is little more tricky to enable
You need to enable it in extension while disable all others including 2nd group from the top which says to always run it for green and red but not for blue

Then you need to go to event sheet disable Auto Tile group
And enable Auto Tile Is On Screen group


I failed at implementing this extension into AutoTile extension so i went with using events sheet for it

If you move around and zoom out you will be able to see where updating ends
But if you move again it will start to lag when you have it zoomed out since you see more tiles so more of them is check
But with default zoom you can really spam a lot of tiles before any FPS drop

  • it does not lag on deleting tiles

Have fun
And thank you for your time and help i really appreciate it

1 Like

I’ll look at your project later. I’m glad you got it working. My time wasn’t wasted. I enjoyed the challenge and I think we both learned something. You need to update as infrequently as possible and with the smallest number of sprites at a time.

You’ll need the initial complete scan and then a more targeted update. You’re getting closer with the “only on screen” update.

1 Like

THX but you are right and wrong at the same time

Is on screen extension is dead end
Problem is more or less this
I 1st moved to check/update tiles on screen then i zoomed out
Now what you see in red area is how big my screen was in moment of check/update
(Check - is when objects get variables depending on adjacent neighbors and that is the most lag causing process here
Update or Set - is when they get proper animation frame which is not performance heavy)
But problem is that it acts as if all tiles beyond screen area + padding in moment of check were not there
Untitled

That’s why you see them being strangely set outside of that area
Now problem is bigger the zoom/screen resolution more objects getting check
I can’t limit checks based on camera position checks because the more far you move the more i would need to set padding on checking with is on screen extension (which adds area of check in pixels screen resolution + padding so 800x600 + 40 padding would be 840x640 area to check for all objects)
Basically it have option to set how many pixels beyond your current visible area check for is object on screen is do something with it
So if i have it set to 40 pixels i need to make sure update on camera position change will happen before camera moves 40 pixels in any direction

If i could limit checking tiles/objects from origin point where they were created on the scene but still take into account adjacent objects then it would not lag at all on creating or destroying tiles and only problem left to solve would be lag on too many tiles on scene

I am thinking about going with OnCreated function and limiting it with that action to check distance between two objects and set it to object to tile distance but idk if that will work or even will it check distance only from created object or all objects of same type for distance
Also i am afraid it will work just as is on screen extension and i will end up with same problem

I gonna do some tests today maybe i will find some solution but all i see is i gonna get same effect as with is on screen extension
But hopefully i am wrong

I went with limiting check to distance between tile and object
Tinting objects show it works

But it seems it checks WHOLE map for objects in that distance
And i guess that is the problem
All events i will make will check whole map instead of chunk of it

1 Like

I looked at your project and nothing jumped out at me. I understand the concept but I’m still a little unsure about the order of events. It seems to be running frequently. I’ll keep looking at it. Dissecting it. If I see anything, I’ll let you know.

On creating object i use these boolean variables to control when will update occur



Same for on object destroyed

I removed boolean update variable from 1st two methods and left it only on IsOnScreen method since i did not see any difference in performance while they were there

Before i had only one method of updating tiles so on created
At beginning of scene i was setting object variable to 0
In other event with At beginning of the scene Inverted (so any object created i was setting their variable to 3)

Then in that update even i simply had it that variable of object = 0 or 4
This way i was updating both game start and while game was running with 1 method

But i wanna share another discovery
I noticed that if i add variable to tile and then change it animation frame
(It is object on creation but after update it is considered as tile)
Then it start lagging faster
Most ideal solution would be to destroy all adjacent tiles on creation of center tile
And then spawn back each object again and change its animation frame
Then i could look for way to apply it to on destruction function
And lag would be next to none

I need to look deeper into the events. If you need to delete and then add objects back then it sounds like an issue with Gdevelop. IDK.

I don’t need i only mean that would be perfect solution
Basically it would be like
You place object which becomes center object and then checks if there is any other object in all 8 direction
If there is destroy them and in their place put new object
And now only that center and any new object which replaced adjacent neighbor of center object would be updated

And that would solve lag problem in creating objects
And there would be no need to check for a way to just place 1 object and then find a way to update only adjacent objects of that 1 single objects

I kinda would wish to cheat my way trough it like that if you know what i meany :wink:

1 Like

Ok don’t it is rabbit hole with dead end

I prepared 4 copies of game
Each is copy of same game where on each instance i simply just removed more stuff

1 - This one is same as you did get from link in previous post but i just removed health behavior from stone and i am using Is on screen method of updating

Number in upper left corner indicates all stones on map/scene
I leave link to test builds + projects to download so if you want you can check it

I was able to have 2.2k stones on map before i get any slowdowns on creation of new stones
But if i don’t hold LMB and just click one by one it is not noticeable
It starts to slowdown badly at around 2.4 so holding LMB enters slug mode while clicking one by one is somewhat acceptable

At 3k stones on map i get slowdown just by walking around without even creating stones

(if you are confused we are not testing here updating slowdown we are testing slowdown that occurs after SOME number of stones already exist on map
Because slowdown on creation and destruction can be acceptable but constant slowdown is not)

2 - Here additionally i went into AutoTile extension and disabled every single event that was there
So for game it should act as if AutoTile extension does not exist

At 3k i started to get slowdowns on constantly creating stones
3,4k slug mode while creating constantly
4,5k slowdowns just walking by without creating new stones

3 - I simply removed AutoTile behvior from stone leaving only Is on screen behavior on stone

At 5,5 i started to feel very very small slowdown
6k enters slug mode
Again if i click 1 by 1 i feel no slowdown
8k i get slowdowns just by walking by not creating new stones

4 - Same as above i just removed is on screen behavior so stone have none behaviors but not to leave it as empty object i added few variables to it

7k i started to feel slowdown on constantly creating new stones
7,2k slug mode
9k i move like slug under water constantly creating stones but i get no slowdown on just walking by without creating stones
I think that is enough for this test

5 - I made one more test just to be sure of variables
In test #4 i had around 15 variables on stone and it started to slow down on 7,2k
Here i removed most variables leaving only 3 of them
And again started to slow down on 7,2k so amount variables do not impact performance

Test results
Test #4 and #5 shows that variables on object change nothing so i can have as many variables as i want on it and do not affect performance
Test #1 and #2 (where difference is 2 was same as 1 while in 2 i simply disabled everything inside AutoTile extension) shows it is little to no impact do you have anything in behavior attached to object
On #1 i had 2,2k stones when started to slowdown on creating stones and 3k when i get slowdowns just by walking
On #2 i had 3k stones when started to slowdown on creating stones and 4,5k when started to slowdown just by walking by
Test #3 with just 1 behavior shows that 5,5k stones on constant creation until it start to slow down and 8k stones until it starts to slowdown when just walking by
Test #4 shows that 1 behavior on object means 7k before it starts to slowdown on creation and IDK how many but more than 9k and is still smooth with just walking by without creating new stones

So in conclusion best performance = use variables and events instead of behaviors
And i think gain between having something in behavior and not (tests 1 and 2) is minimal
So using 1 behavior on object (i need to combine is on screen with AutoTile) would be best solution for releasing extension
While best thing to do is go with example project for ppl to copy instead of giving them extension
Extension would make sense for small maps but idk who is gonna use it for small maps

So we would waste time trying to find way to reduce creation/deletion slowdown while real problems is from how much behaviors you have on object

I gonna release AutoTile with combined is on screen and warn ppl to go with small maps and keep game zoomed in
But i think i gonna do example project for Auto Tile for best performance and go this route with my game

Thank you Keith you have no idea how you helped me (i still have your project for detecting adjacent objects and gonna use it for something else)

I am happy i decided to waste time on these test before we would waste days trying to find slowdown solution
I for sure learned that if you wanna have tons of stuff on screen then don’t give it behaviors but instead go with variables

Kinda useful info i gonna do bullet hell one day

Have fun and i hope you enjoyed it also :wink:

1 Like

@Keith_1357 Tell me do you wanna me to share stuff like that below or you already know more than you need?
Since IDK if that is useful info for you or not
For me it is since it is de-slowdown knowledge and anything that makes your game run smoother is valuable knowledge in my eyes

Anyway i just edited that cursor of mine to spawn 8 objects at once in addition to that 1 in the center so 9 in total

I noticed that slowdown on creation does not come from creating new objects
It comes from whatever i have in creation event

If i just click LMB then release then click again instead of holding it
I have no slowdowns at all
As you see in events no new objects can be created if selector is in collision with object (sand in this case)
But if i have selector on that object and hold LMB game literally drops FPS
So all the slowdowns that started at creating objects in tests above did not come from objects themselves
If i would need to guess it is because collision check event miss trigger once but if i put it there i can’t create new objects

And i think that collision check is source of slowdown on creation
Whatever but i was able to walk freely with no slowdown around with 12k objects on screen
I had no patience to spam more
But i think i need to expand number of how many objects that cursor create and check what is the limit if any

Now i do believe with some tricks it is possible to create whole map from tiles
With some tricks ofcourse
For example grass don’t need to be tile it can be just background color
And if i wanna dig dirt (destroy gras) i would simply just spawn dirt tile in that grid cell
Other thing to do is 1 tile at a time in grid cell
So for example stone tile wound not have below dirt or grass
Tree tile would not have grass or dirt under it
And considering even map like 800x600 most of it would be free space to walk
So it could be really smooth experience
Not to mention i found chunk system GDevelop OpenWorld Example Using Static Chunking by danogster
So maybe i could spam as much objects as i want
IDK i need to do a lot of tests

1 Like