Hi Guys, I’m new to UE5, recently I’m trying to implement a temporary perks system through blueprints.
At the moment I’m trying to make one that reduces the life of zombies (yes, like Instant Kill from COD.)
But, kind work but only for one zombie.
if i have 3 zombies on map, the first one dies with one shot and the other 2 die according to the normal damage system.
I’m using this code in the the AI character blueprint, it is called through a event dispatcher that is activated when I overlap the icon in the world
The most important bit here is the bind itself. Can we see it?
Is there a reason why this needs to work this way? Why not let the player use a special Damage Type zombies interpret as insta-kill. This way they can keep their health, no need to dispatch anything. They are simply dealt as much damage as they have health.
If you’re referring to this Zombie Base leaving the cast node, the logic in my head was;
All the logic would only be triggered if the player passed over the overlap actor, that’s why I made the cast. and then I got the zombie variable which is where the event dispatcher is. inside the Zombie character. I didn’t want to make two casts within the overlap actor.
Using these Apply Damage and Any Damage nodes would actually be easier. it seems. but I was following those “Create an FPS” courses. and in this course the instructor created a somewhat complex Health system so I don’t know if I could adapt and make everything work.
Coming back to the main topic. For the dispatcher to work, you need to bind it. We’ve yet to see you do it, though. Could you show how you register the event?
Atm, you are clearly sending a message to a single zombie instance - something you should not be doing at all for this to work.
all zombies register with a dispatcher (can we see how you do this)
player calls the dispatcher / or picking up an item calls the dispatcher
That’s it.
You said you work with a temporary perk system, why not give this perk to the player instead? Player gets a perk to insta-kill zombies. Why spam all 4000 zombies we may not even get to see?
I hope you see what I mean.
You could make it work the way you want, it just seems unnecessarily convoluted. But it could work, sure. Ensure the zombies register with the dispatcher first. Then call it.
I don’t know exactly what “how you register the event” means
As I said I’m new to Unreal and English is not my native language.
so I don’t know if that’s what you meant but the event is called by the event tick
Regarding the Zombie instances, I only have one. I just copy it and paste it on map. So it wasn’t supposed to work since they are the same zombies using the same code?
I don’t really know what I’m doing. When I think about killing zombies more easily, I immediately think about reducing their health.
I totally understand you and it doesn’t have to be the way I’m trying to do it.
I wonder how I could make it work by giving this perk to the player instead of changing the zombies health?
You said up above that you have three zombies.
A blueprint is a class but actors are objects (which are instances of the class.)
When you get “a BP_Zombie” in the node graph, you’re getting the instance not the class. Any changes you make, only happen to that one instance, not to all objects of that instance.
If you need some parameter that affects all objects of some instance, typically the best place to put that, is in your GameMode.
E g, Zombie would know “how many hitpoints do I have?” by asking the GameMode for the ZombieHitpoints parameter you add there, and then when the player gets the power-up, you change that value on the GameMode instance. (The reason this works, is that there is only ever one “the” GameMode instance, even though the GameMode blueprint is still a class, and the GameMode itself is an instance of that class.)
I am specifically avoiding enemy class inheritance, treat Zombie as the base enemy class; here to make it more relatable. Do note that what’s below may seem complicated at a glance because it’s not a solution to your specific issue, it’s a solution to 99% of issues in vast majority of scenarios where damage needs dealing.
This is still somewhat simplified and can be improved further but that should be tackled once we know the scope of the project.
Consider the following:
I’ve created an enumerator (official) so I can distinguish between enemy and damage types easily:
The base enemy class has this variable, each enemy knows who they are if we query them. This one is a zombie:
We use our damage class for processing (see above).
the interesting part kicks in when we start using other damage type classes. This is the damage type that allows us to immediately kill zombies (and zombies only!):
Note how all the processing, damage mitigation, crits, health can be handled inside the damage classes. We no longer need to clutter the enemies or the player with any of this.
Also, note how we do not need to inform the enemies about any of this. They will deal with the damage when it happens.
The above can be combined with dynamically spawned actor components. This would then work like true perks - where the player gets any number of temporary or persistent abilities.
Just an update, it worked like a charm. At first glance I thought it would be too complex for me to reproduce in my project but it worked very well. So once again, thank you.