YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
13 stars 5 forks source link

Changing a depth of an object changes its layer #2527

Closed Romualdo666 closed 5 months ago

Romualdo666 commented 5 months ago

Description

The title may sound stupid, but I had to summarize the problem in general;

Basically, if you create a layer with layer_create and then you add an object to it with instance_create_layer, the newly created object will be removed from this layer if you change its depth RIGHT AFTER it was created. This means, NOT on its Create event nor other events. It could not be a bug and may be intended, but it's kinda confusing and I believe that specifying this on the manual could be helpful.

Also, once you change its depth the moment it gets created, if you also check if the object is present on the layer that same moment, it'll return positive. The game seems to change its layer a frame after this happens, very odd too.

Steps To Reproduce

Create an instance with instance_create_layer, change that instance's depth on the same frame you created it. A frame after, try to delete the new layer. You'll notice the object will not get destroyed.

2b4a0f41-7e07-4b96-872d-5f824c36a7f3

Romualdo666 commented 5 months ago

just did some testing around, and apparently it isn't about changing the instance's depth once it gets created. The issue is changing the instance's depth externally; meaning, another instance changing the new instance's depth.

yoshikins commented 5 months ago

iirc this is somewhat intended behavior. When you change the depth of an instance, the instance is put on a managed layer at the specified depth, even if a user-defined layer exists at that depth. When you change the depth of an instance, you are also inadvertently changing the layer the instance is on, so any layer functions would no longer apply to that instance. You could probably see this behavior in the attached project by comparing the layer value before and after changing the depth of the instance.

This behavior is also mentioned in manual: image

Romualdo666 commented 5 months ago

but why does it only happen when you change its depth from an external instance?

like, if you change the depth of said instance using a different instance, it does change the layer; but if the instance changes its depth by itself, it stays on the layer. Is that intended as well or what?

yoshikins commented 5 months ago

I can't seem to replicate this behavior at all. I don't have access to the base project, but with my own tests I get these results: image OBJ 1 is created from an external instance, has its depth manipulated from that object on the same frame it's created, and its layer and depth are recorded both on the same frame it's changed and recorded 1 frame after. OBJ 2 is created from an external object but has its depth manipulated from within itself, and not an external instance, then its layer and depth are recorded both instantly, and 1 frame after, and the results are the consistent.

Idk if this is documented behavior but the results aren't unexpected, whenever you change the depth, layer, or deactivate/reactivate an instance the effects don't tend to take place until the next event or the next frame. There must be something else going on in your project to cause this behavior. I do think it should be looked into.

Romualdo666 commented 5 months ago

i made a completely new project and it worked. let me just tell you the code

Object 1: Create event

layer_create(1, "test) with instance_create_layer(0, 0, "test", Object2) depth = 2 alarm[0] = 30

Object 1: Alarm0 event layer_destroy("test")

you'll notice how object wont get destroyed

now, a different case.

Object 1: Create event

layer_create(1, "test) instance_create_layer(0, 0, "test", Object2) alarm[0] = 30

Object 2: Step event

depth = 3

Object 1: Alarm0 event

layer_destroy("test")

Romualdo666 commented 5 months ago

sorry it looks bad, and theres a chance it doesnt even work. it's because i'm not at home and did this from memory on phone

yoshikins commented 5 months ago

I'll give it a look

yoshikins commented 5 months ago

Just by looking at the code you have here, I don't think any of the behavior is unintended or bugged. By changing the instance's depth you are changing the layer it's on, so destroying a layer that it's no longer on shouldn't affect the instance at all. In both cases you presented, the instance won't get destroyed, and I can verify here.

depth-test.zip

Romualdo666 commented 5 months ago

i swear i did something like this and in the 2nd example it'd get destroyed. i'll see if i can make a drive link when i get home

On Mon, Dec 18, 2023, 20:31 Yoshikins @.***> wrote:

Just by looking at the code you have here, I don't think any of the behavior is unintended or bugged. By changing the instance's depth you are changing the layer it's on, so destroying a layer that it's no longer on shouldn't affect the instance at all. In both cases you presented, the instance won't get destroyed, and I can verify here.

depth-test.zip https://github.com/YoYoGames/GameMaker-Bugs/files/13709411/depth-test.zip

— Reply to this email directly, view it on GitHub https://github.com/YoYoGames/GameMaker-Bugs/issues/2527#issuecomment-1861854181, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWZBU3T6GTFQ746TF56NZOLYKDG6XAVCNFSM6AAAAABAZSDB7SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRRHA2TIMJYGE . You are receiving this because you authored the thread.Message ID: @.***>

Romualdo666 commented 5 months ago

actually, now that i thinl abt it... i could've messed up making some unreachable code or something. I think i'll close this issue until i can fully confirm this (when i get home). sorry if i wasted your time