Trouble when removing component

Hey guys !

I recently came across a situation that I don’t even know how to deal with.
Let say that my issue is about a “Shooting Situation” where i need to create a shot ( for now it’s just spawning a particle beam ). For this, i made an event that creates a laser beam ( spawning with a delay of 1 second before gettin removed)

My problem intervenes when I call this event faster than 1 second ( delay of destruction ).

  • For instance if i decide to call this event to shot every 0.5 sec, then in this case i’ll have 2 lasers created in 1 sec.
    Only the last laser created will be removed.

Details : ( given by simulation )

  • Event “shooting” is called every 0.5 sec

  • So when it’s called it reaches the delay to 0.5 on 1 sec. That’s because the event is called again.
    So it does not reach the “destroy component” function

  • So to be clear i’m searching for a solution that forces the event to be superposable without interfering with itself.

It seems to be a basic situation but I don’t even know how to fix that.

I would really appreciate some feedback about that.

Thank you.

Thank you Thompson. It’s for a turret weapon. Unfortunatly my code is a bit complexe, so i just skipped a huge part to keep the system simple.
But to give you an idea, even if I use a simple system like you described ( mouse clicked to create laser beam) if my shooting rate (finger) is higher than the delay, only the last shot will be removed … :S

but if it were like i said it wouldnt matter because there would be no delay. the way i was saying it, when the mouse button is pressed it would create the beam then when the mouse is released it would destroy the beam. in this way you would never be able to be quicker because as soon as you let off the button it would destroy the actor.

does auto destroy not work? or could you set a lifespan on the emitter so it would handle destroying itself. or you could make the emitter a seperate BP

It’s definitly a good idea but it’s an automatic weapon.
So if I keep the left mouse button held down , it’s calling multiple times the shooting event ! :smiley:
So i can’t really use this solution

That’s exacly what i’m looking for. I need the event to create a unique and independant laser every time i call the event. I’ve never heard about the lifespawn thing can you give me more details about that :smiley: ?

Lifespan essentially creates a timer that counts down and when it reaches zero the actor is destroyed. not sure you can do it with a component but you could easily make your projectile its own BP.

I see now you want your gun to fire like a full machine gun whereas i was thinking wither semi auto or something akin to the link gun unreal tournament.

Argh ;s This is for actor only. A componant such as a particle system can not benefit from this. But i really appreciate your help !!

so just make it a separate actor in that case just like how the projectiles are in the first person template

Yep thank you :smiley: Can i ask you another thing. I firstly decided to go for a particle system because i could create a sort of beam. But if i do it with actor/projectiles, can I also make some kind of beam ? ( I’ve never used that thing before )
I need to create a beam between tow points in space.

really depends on what you mean by beam. if you want constant lightning between two points it could go either way but a particle would look nicer. if you want a single bolt of a defined size and shape to fly from point a to be then you could use a mesh. its really hard to say, even more so since i havent done work with any kind of beam. i would say if you know how to make the particle system then go with that rouse since it will probably look better. but then again you could always get really creative with some scripting and come up with anything

That’s what I thought. It’s definitely better in my situation to keep using a particle system ( cause i’m controlling a start point and a end point ). So I still need to find a way to remove / kill my particle when created.

you can still have it as a particle and it be its own actor bp.

Omg I didn’t know that ! I’ll give it a try :smiley:

yea you can make pretty much anything an actor or attach it to an empty actor.

Thank you very much for your help.
To recap, i’ve been creating a BP for the lasershot. ( it’s basically just a particle system ). It works well with the life span function !!! :smiley:

I also take this opportunity to ask you how can I control the end point of this particle now that it is set up as a blueprint ?? :smiley:

how did you control it before? there are many ways to accomplish setting the start and end but its the end result that matters so lets base it off what you know already .

Because my particle system is set up as a “Beam Particle” there is a function named set beam end point ( Set Beam End Point | Unreal Engine Documentation )

My beam start point and end point are calculted in my turret blueprint. I can easly calcule the length between those two points and give it to the new blueprint, but I have no idea how to do that ahah.

(To be honest i’m quite a noob to unreal, even if i know how to code, i still have to get use to the engine structure to understand how things are linked and how it communicates between blueprint :slight_smile: So i would say now that i need to work with 2 BP i’m quite lost xD

in this case it should be pretty easy you say you had variables for the start and end points before well create the same variables in your lazershotbp. now im guessing your using a spawn actor node to spawn your lazershot actor. if you are then just drag off the blue return pin and search for set then the name of the variable. if all went as planned you can now set the start and end point easily from the original blueprint.
dont feel bad not knowing stuff ive been working in the engine off and on for about a year and i still dont know how some things work.

Is this for a gun? if it is you could just have it spawn and all that on key press then destroy on key released.