Keeping track of multiple spawned objects [Solved]

I have an event that spawns a physics projectile, then checks it for collisions and when it hits something calls another event and removes the projectile. However, i need to be able to have more than one of this projectiles at once, but it can only check for collisions on the last spawned object.

Is there a way of doing this other than copying the event for every projectile that can exist at once and calling a different event for each subsequent projectile?

1 Like

The way that I would do it is to add a trait to the object that you spawn that handles the collision logic. I like try to organize the logic and traits so that each object mostly looks out for itself. So if I have a bullet, I give that bullet a ā€œBulletā€ trait that handles its expire time, its collisions, and its movement speed. I also have a gun, and I give that gun a ā€œGunā€ trait, that handles listening for trigger pulls and spawning bullet objects. If the ā€œbulletā€ object that you spawn has the ā€œBulletā€ trait applied to it, then every spawned bullet will also have that trait and will therefore behave like a bullet, which disappears and spawns an explosion on contact.

2 Likes

I see, thatā€™s just what i needed, thanks again. Iā€™ll take a deeper look at how traits work.

2 Likes

How can i refer a node to the spawned object when itā€™s on another node tree? If i refer to the original then itā€™s only applied to it

Sorry, I donā€™t understand exactly what you mean. Could you elaborate a little?

Letā€™s say i want to use a set velocity node to get the spawned object moving, for example.
What should i connect to the set velocity object input?

Here is a screenshot of my Bullet node tree:

This trait simply removes the bullet when it hits something, and it moves the bullet at a speed of 100 in the bullets look direction ( local positive Y direction ).

For my gun I have the following trait:

image

This just spawns the bullet and sets its transform to the transform of the gun ( this should probably be the transform of an empty in front of the gun instead ). When the bullet is spawned it will already be pointing the the same direction of the gun, and the ā€œBulletā€ trait will handle setting its velocity to 100 units/second in the direction it is pointing.

3 Likes

The ā€˜Selfā€™ node is what i was after, i missed it since i was finding for something with Object in the name. This clears that out.

2 Likes

BTW If you leave any object selection field in a node blank, it will default to self. That can help make node trees a little more readable sometimes.

1 Like