Attach actors to a Pawn?

Hello everyone.

I’m working on a game that involves physics based space craft but I have a problem. The idea I had was to make a skeleton on a ship (Done) and attach armor plates to it fall off when shot (done).
However, it seems I have to individually add static mesh to the pawn and then individually write something in the blueprint for each plate. I got it working but Its not convenient to repeat it 20+ times, so I’m wondering if there is another way to do it, since all the armour plates should act the same way. I want to make the plates an individual actor, which can be scripted and then added to the ship and literally pasted around.

This is what I was doing (sorry for the mess): 53dc7280e42ad9da71ee453fe23d992847eccb15.png
And this is what I’m trying to do with the plates UE4-2.png

You can create a custom event with hp / component and other info needed in input, on component hit, you call the custom event with the right infos.

You may can too do an event hit, check which component and from it do same as before but i am not sure the best way to do it.(only an idea on the fly)

I’d go for a custom event too, but do anyone knows enough about “delegate” to tell me if that would be a good way to go ?
Or with event binding ?

Ok, so would I add the custom event to the pawn and connect it to the meshes of the plates? I just don’t want to have to repeat the script 20+ times for each mesh.
The script that I posted works, and is exactly what I’m trying to do but I just want to know if there’s a way of making the meshes its own actor with one of those scripts I posted, so I can duplicate it over the ship and each mesh will act the same, but will be separate with its own variables. I tried an actor, and got the script working but I couldn’t add it as a component to the pawn.

I hope it makes sense

With the custom event logic, you’d have to launch the event for each plate, but the actual script would only have to be written (or tweaked) once.

Okay, so how and where would I set up a custom event?

This is something you should learn for good so you should go and watch a few tutorials.
I can give you a quick how-to since I imagine you’re pretty impatient to see your stuff working, but you should really go asap and get a deeper understanding of this system.

So you just right clic somewhere in your BP, and type “custom” from there, you’ll find a “add custom event” node
Place it, name it, for exemple “BoxHit”
In the detail panel of that event, add an input, with an actor type. Call it “box” for example. You’ll probably need some more of those later depending on qhat you want to do.
Later, you’ll plug this event in place of the hit event you currently have. And Use the “box” output as the actor you want to affect (detach or anything)


Now it’s created, you need to call it.
From one of yout hit event, drag the execution pin, and type the name on your event, “BoxHit” from my example. You’ll find it under “call function”.
It’s created and called when the hit event is launched. Plug a reference to the box that’s been hit in the “box” input you created previously.
Repeat those two last steps for each one of your box.

So yes, only the script itself will be unique and you’ll still have to launch this event for each one of your box. But if you want to change the actual script, you’ll only have to do it once. And maybe the event binding I talked about earlier is a solution so you don’'t even have to do that, check if you have time.

Thanks for the reply, I’ll try it out, and yes, I will try to develop a better understanding of how it works :slight_smile:

Small question, when you mentioned adding an input with an actor type, do I change NewParam to Object Reference/Actor or do I create a new actor with the desired script?

I think I understand how it works, but Will the event share its own variables, or do i need to make a new one for each box?

When the event is called, it will be “carrying” the value you set as an input with it from where it’s called. Was that your question ? This input is the closest thing you’ll have from a variable.

When the box is hit 5 times, it should detach from the parent. I’m just wondering if I need to make a separate variable for each box (I don’t want them all falling off when one is hit 5 times, if you know what I mean)

It would be helpful if individual components of a pawn could have their own event graph

Why don’t you make a separate blueprint for just the armor plates. Create an integer variable and set it’s default value to 5. Then create a on hit event, set the integer to subtract by -1 each time it is hit. When the integer value falls down to 0, set the simulate physics on and destroy the plates after x seconds.

Thats what I’m trying to do but I don’t know how

This is how I’d do it.

I mean, I’m unsure what you mean by a separate blueprint for the armor plates. Also, thank you for the suggestion for a good system :slight_smile: