#[SOLVED] WHY EXPLOSION INSTANCE AFFECTS OTHER INSTANCES
1 messages · Page 1 of 1 (latest)
2 - when bullet explodes: it expands its circle shape:
i connected the "frame changed" signal from animated sprite 2d, so each time the explosion sprite changes, the circle shape expands as you see in the print.
THE ISSUE:
when i shoot a bullet and a new explosion happens, the bullets that already exploded redo the method update_explosion_interaction_each_frame() and i don't understand why.
i tried some code to verify if it already exploded, but no success
note that i already know the solution would be using "queue free", which i will do in my code anyways, so it is not a big problem actually.
i just made this question because i found it an interesting behavior and want to understand why it happens
well you said it yourself. If the bullet is instantiated and it's not freed, they will keep executing the functions until they are freed
And you haven't made the scenes resources local to that scene
Indeed, but i think each instance shouldn't be affecting other instance. Since each instance is an unique object, it should identify what object is calling the method, not triggering all objects existing in the node tree. That's what i find strange
What you mean exactly? For each bullet i create an instance, i add it to the node tree by "get_parent().add_child(bullet)"
So i suppose they are in the same family
I don't know exactly how your bullet is structured but if you're changing the size of the radius of the collusionshape
then if you click the collisionshape and go here in the inspector you should be able to make it unique per scene
Otherwise you're using the same resource for each instance of the scene, which is done automatically to save resources
That said I'd have to have your project to understand why the frame index seems to be resetting, though it's unlikely it actually is resetting and it's just because of the resource as I said previously
I guess I missread the problem
I think a lot of the ambiguous behavior comes from the var bullet = Bullet.instantiate() line and the actual "Bullet" packed scene. Is Bullet a class (style suggests it is) or a const preload/load of the packed scene? If it is a class, I don't think it has "instantiate" as a function regularly, so what is that function actually doing? Secondly, what is the node tree of the typical bullet? Why not just have the script attached to the base bullet node instead of its child.
Finally, can you do a screengrab of the remote view of the scene tree while both explosions are occuring and/or put a codebreak in update_explosion_interaction_each_frame to see if it runs a single time and updating a shared resource (most likely) or running twice in one frame and updating separate resources?
i tried it and it worked, thank you all @digital turtle, @violet grail and @sick patio for the support and patience
[SOLVED] WHY EXPLOSION INSTANCE AFFECTS OTHER INSTANCES
I did nothing XD
I'd feel bad for not answering seeing that you spent time trying to understand my situation, but you don't need to read. the messages bellow.
"Is Bullet a class (style suggests it is) or a const preload/load of the packed scene? "
It is a preLoad of a Packed Scene
"so what is that function actually doing? "
shoot: shoots a bullet based where character is looking at (x and y point)
"what is the node tree of the typical bullet?"
-characterBody2d
--Node2d (with script containg all bullet behavior)
-- sprite 2d (the bullet)
--animated sprite 2d (when exploding, plays this animation)
--area2d
----collisionSHape2d
--timer
" Why not just have the script attached to the base bullet node instead of its child. "
it was a mistake i made, i created a base class for inheritance (to work like an interface).
but since each bullet have different properties, making the root (characterbody 2d) inheriting it was strange, so i thought it would be better doing a more generic node inheriting it
"do a screengrab of the remote view of the scene tree while both explosions are occuring and/or put a codebreak in update_explosion_interaction_each_frame to see if it runs a single time and updating a shared resource (most likely) or running twice in one frame and updating separate resources"
i also tried that, but couldn't find why, it would happen just when the new node enters the tree, i saw the nodes IDs and all were different.
After searching a bit in the internet about signals and how it triggers, and reading a bit more about the solution ofFatreh, i ended up in the conclusion that godot triggers it regardless of instances, but i think it would be necessary to explain why. Once again, i thank you for the time trying to help me earlier.