Adding different points depends on the enemy

I want to get 100 points when I kill the enemy, but I want to get 200 points when I kill the koopa, I couldn’t make the difference. thx for help. i tried something after this but didnt work

Cast Failed pin on the cast ot BP_Enemy should go to Cast BP_Koopa and it should work assuming you have your overlap collisions (and enabled events) setup properly.

Oh and you have to move your cast to Third person character at the start of your graph or you’ll skip it on the koopa path.

You may want to have a common base class for enemies where you can just set the points on each type of enemies. Or use an interface.

1 Like

Hey @Dozzirik how are you??

There are a couple of problems that prevent you from adding points the way you want:

  1. The cast to Koopa is not connected to anything

  2. You should check for the koopa before checking for other enemies (I’ll show you later on this post)

  3. You should use the casts to change a variable with points and then add that variable

  4. You should store the actor you found to destroy it later without any issues

Your blueprint should look something like this:

As you can see, I first check if the fireball is overlapping a “koopa”, but if the cast fails I cast it to “enemy”.

After checking, I set the “Overlapped Enemy” variable (of type “Actor”) to the corresponding overlapped actor. Then, I set the “Points Granted” variable (of type “int”) to 100 or 200 depending on the overlapped actor, and after that, I add the points based on that variable. Lastly, I check if the actor is still available (I could have been destroyed before this part of the code by other effects), and then I destroy it.

That should work as you want!

Let me know if you need more help!

Edit: I forgot to include the cast to “ThirdPersonCharacter” but you can do it before adding points as in your screenshots!

im good what about uuu?

i tried like this before u answer

it works like i want but when i close the game it gives error like this.
Blueprint Runtime Error: “Accessed None trying to read property K2Node_DynamicCast_AsBP_Koopa”. Blueprint: BP_Fireball Function: Execute Ubergraph BP Fireball Graph: EventGraph Node: DestroyActor how can i fix it

1 Like

Hello again!

That error happens when you try to destroy an actor that doesn’t exist. In this case, your fireball overlapped with a BP_Enemy and NOT with a BP_Koopa. So, when you try to destroy a BP_Koopa, its reference doesn’t exist. That’s the reason why you should store the actor as a variable and check if it is valid before destroying, as I showed in my version of the code!

Hope this helps!

1 Like

yeaaa makes sensee