I want to make a character blueprint that has other character blueprints as “child actors”.
These child actors have a float value that, when it reaches 0, they “die”.
I want to make them DETACH from their parent when they “die”. Is that possible?
Hi,
tbh, I’m not a huge fan of Child Actors. The idea is great, but proved to be troublesome in my experience.
Anyway, in your case it seems you should just spawn the actor you want and attach it manually to have a full control over it. This way you can detach it anytime you want with simple Detach function.
You can try to detach child actor but not sure if that’s possible (I can’t open UE right now), but that just doesn’t sounds like a good idea to detach component from its owner.
I was asking for clarification about what you intend for this relationship to mean, as in, does the child follow the parents transformation?
That is typically what it would mean but you were vague so I wanted to clarify.
I understand what you mean now though, and I agree with above: don’t bother with the child actor thing because it will add more complications than necessary.
In the blueprint of the thing that can die and follows some other actor, just use a Attach Actor to Actor (there are some other attach nodes as well) node and get a reference to the one that you wish to be the parent.
In my case, I used Attach Actor to Component, that way I can use a scene component to define a specific place to attach the actor.
Another important benefit to keeping the actors separated this way is that you’ll be able to refactor this all so that the two classes never need to know about each other. In blueprint you can accomplish that sort of decoupling using interfaces. I don’t believe you would be able to accomplish that using the Child Actor feature.
I have a unit of soldiers that is character blueprints.
I’m not using any AI; I just parent all 100 or more characters into a single character and move them around with keyframes.
The problem is that when a character “dies”, the whole unit moves, dragging the dead character with it.
Using methods other than parenting is problematic because I would need to figure out how to make the characters move in formation, utilising some form of navigation. I tried a lot to achieve something like that to no avail.
So, is there a way to make 150-character blueprints, following a single-parent character blueprint, using your above method?
I can’t precisely understand how to implement such a system method in my specific situation.
Yeah, this method will 100% work in your case. You just need to spawn your 100+ characters instead of adding them as components.
However, sorry for little sidetrack: Character class is quite heavy. If you are making RTS style game, or something with couple of houndreds of characters, it can turn out to be a performance issue.
It’s ok for prototyping as it’s easy to use with a lot of built-in systems, but as you move further into development consider using Pawns or just Actors, depending on functionalities you need.
Ok, so that’s not really a game and you are not really comfortable with scripting math?
In that case, I think you could just replace your child actors with Scene Component and tag them as “UnitSpawnPoint” or something, then on Begin Play gather all Scene Components with this tag (GetComponentsWithTag) and in ForEachLoop call SpawnActorFromClass using the transform of every scene component.
Remember to set Actor Class to your own character class.
Yeah if i understand what lordlolek is describing correctly, you essentially just setup your formation with scene components (and you can animate them or w/e you want to do).
For each scene component, spawn an actor and then attach the actor to the scene component.
if its not a game you dont have to worry about optimizing it beyond that really, I wouldn’t think.
This will work the same as child actors, except you will be able to use the detach node and it should work.
Thank you very much both for your helpful replies!
The problem is that I’m not exactly sure how to achieve this without a step-by-step guide…lol
So, if I understand correctly,
I’ll have to create my parent character blueprint.
I’ll create multiple scene components within the parent character blueprint.
Then I’ll tag all those components with a specific name.
Here is where I’m not sure what I’m supposed to do though .
In the event begin play (I’ll make a custom one since I’m already using the default), I need to add the code you are showing in the screenshot below. But I see there is a set from an array.
Is this array automatically available from the tagged components?
Also, I reckon that I’m using the “Character_Blueprint”.class.
These scene components are to be positioned by me within the blueprint, I guess?
Finally, I don’t precisely understand how I will replace the scene components with my desired character_blueprints -soldiers.
There are many things I don’t precisely understand with this solution.
I would have tried to complete my knowledge gaps with YouTube tutorials, but try as I might, I could not find anything even remotely useful for my specific situation.
If the number of scene components and number of entries in the Soldiers array is not the same, you’ll need some additional code to handle that, otherwise you’ll get some errors about indexes not found. That’s another problem, but if you search for something like “loop through array” I think you’ll find answers. A simple solution is just to add more entrees to the array so that they both have the same number.
I’ll try to thoroughly examine what you are describing here and let you know about the results.
Still not exactly sure how to do a few things but only testing this will give me specific answers.
The pros are that the Character blueprint I’m using successfully spawns other character_BPs around it where I’ve placed the scene components.
The cons, though, are that 1) I can’t get the “death” reference from the spawned Character_BP’s since their “death” occurs within their blueprint event graph.
The spawned character blueprints don’t have their gravity nor follow a landscape’s sloping surface. Instead, they blindly follow the “parent” and their position dictated by the scene component.
I believe you are struggling to link up the soldiers’ death events because you’re trying to call DetachFromActor in the parent blueprint, rather than the children. From the tooltip:
“Detaches the RootComponent of this Actor from any SceneComponent it is currently attached to.”
Below I have created a character blueprint since I assume that’s what you’re using for your individual soldiers:
I call DetachFromActor from my OnDeath custom event, which you would replace with whatever you are using to manage your death system.
Gravity is faked by tracing down from above the spawn location, and setting the soldier’s relative location accordingly. I use a sphere trace with a radius equal to that of the character’s collision. When setting the relative offset I use
hit location + capsule half height - capsule radius
in order to account for the radius included in the sphere trace.
The variable SpawnPoint is a Scene Component Object Reference, with Instance Editable and Expose on Spawn both checked - this is so that I can pass in a reference to the appropriate scene component when I spawn the soldier actor from within the parent blueprint, as shown below:
Adding a branch to prevent the soldier from performing the line trace, and setting the detachment rules to Keep World prevents any untoward behaviour, although I must admit the idea of the soldiers going literally six feet under upon death is rather amusing.
This needs a lot of investigation.
There a few things that I’ll need to figure out here in trying to adjust this system to my own.
I’ll test it thoroughly and let you know about the results.