Weapons disappear randomly/weird glitch

Hi, me again, sorry!
I have strange and specific problem. I have the weapons of my player as separate sprites set to follow the player and act accordingly based on code and yada yada. Problem is, when my player walks to far from a certain point, the weapon disappears. If I attack or do something with the weapon, it comes back, then disappears again when I’ve walked too far from the point I last used it. I checked, and it’s not a timing thing. Also, z-orders for the weapon sprites get messed up in a similar way.

I’m not entirely sure where in my code this problem is, so I wanted to ask someone who’s more knowledgeable about it. I have a LOT of code for my player character, so I thought it’d be easier to give you the actual code itself to copy/paste into gdevelop so you can get a better look than if I just gave pictures.

Apologies for the ugly mess below:
Code has been deleted, since copy/pasting doesn’t work for it. I have pictures below, tho.

Your raw paste doesn’t seem to work, so… :man_shrugging:
Open your debugger and check the position and z-order of your missing object, maybe it’ll help you figure out what’s wrong.

I checked the debugger as you said. All I was able to determine is what I already know, which is that the weapon disappears when I head a certain distance from where it was last used/summoned. If I go back into that square area (it’s really more like a rectangle, actually) the weapon reappears, no matter which one I’m on. I did manage to get the z-order thing working somewhat better, though. I just can’t wrap my head around where possibly in my code this first problem could be coming from though.

I’ve uploaded pictures. I’ll edit my main post to take out the copy/paste code since it doesn’t work.

“Disappears” doesn’t exist in the debugger. I meant to check if the object A) exists, B) is not hidden, C) is on the right layer, and D) its z-order is okay.
Looking at your events… why are you setting the z-order to the Y position?! :face_with_raised_eyebrow:

Just checked the debugger again. I made my player stand within the area the weapon appears and outside of that area, where the weapon doesn’t show to compare the debugger info. Both in and out of the area, the object still shows as existing, has “false” under the “is hidden?” field and remains on the same layer. The z-order changes, though, as is to be expected, since I coded it in.

I have the z-order set to the y-position because I’m creating a top-down, and that’s the simplest way I’ve found to make sure all the NPCs, enemies, player characters etc. can stand behind each other and the props and actually appear to be doing so. Otherwise, it gets very complicated very fast to have set layers for different things, which I tired doing, but I realized this method is better and less of a headache. Also, way less code.

OK. So, the z-order changes as expected. But it’s not visible anymore, so something is in front of it, right? So your z calculations have a problem, no?
If two objects are superposed and have the same z-order, they compete for visibility. You need to clear such conflicts.
I can’t find in your events some condition about player position or distance, so I don’t know how you handle that spawn area thing.
Feel free to share more screenshots (including preview) or the project’s folder.

Yeah, I think the z-order is working perfectly well. Even if the weapon was behind the player z-orders-wise, it would still be visible, because none of the player sprites completely cover the weapon in most cases. Since the weapon is set to rotate towards the mouse, even if it hid behind the player, I should just be able to rotate it out with the mouse so it becomes visible again. I did a play test where I hid the player sprite, and the weapon still behaved the same, so now I know it’s not just hiding behind the player in some way.

How do I upload the project, as a ZIP?

I didn’t mean the player necessarily. I haven’t seen the game… maybe there’s a background?
You can upload as zip on easyupload.io or such.

Here you go. Apologies for the messiness of everything.

OK, I found your issue.
First, you can’t have one object with animations of different sizes.
Second, the objects that have a hitbox setting need a hitbox, you can’t leave that empty.

So, remove the bow from the weapon object, or adjust the size of its sprites.
And if you don’t want the hitbox of the weapon to work, use conditions to only enable it when you want to.
Also, go to Resources tab, and remove the unused resources, they will create issues, sooner or later.