Switch from a projectile to another

Hi people, I’m sorry for my bad English but I think you can understand and help me.

Firstly: I’m an UE4 newbie :smiley:

I’ve these Blueprints:

1- Projectile 1

2- Projectile 2

3- Pickup Actor

4- Spawn Projectile (inside my Character Blueprint)

Every time I press “Left Mouse Button”, my character spawn a “Projectile 1”.

Now I would switch from “Projectile 1” to “Projectile 2” when I destroy my “Pickup Actor”.

I’ve tried for six hours without success :frowning:

I hope you can help me…I think it’s easy for you :slight_smile:

Actually its quite simple.

You can change the Spawned projectile class by feeding an input to the ‘Class’ node of ‘Spawn Projectile’. OR you can do a branch (if) and based on whather your Pickup Actor is destroyed or not, call ‘Spawn Porjectile’ with different classes. So you will have two instances of ‘Spawn Projectile’ node. One will have its class set to ‘Projectile 1’, the other will have ‘Projectile 2’. You connect node 1 to the ‘True’ output of Branch and node2 to ‘False’ output.

The important part is the ‘Condition’ pin of the branch. This is where you determine if your Pickup actor is destroyed or not. To do that you could either set a boolean flag in the class (and set its value from the Hit Vent Grpah you have shown) OR hold a reference to the Pickup actor and test if its Valid. See if you can make it work…if not, let me know.

Hi Mindfane, many thanks for your answer!
I’ve tried something but I think I’m wrong with the Condition pin of the Branch.

I need something like this:

This Blueprint spawn random classes (I’ve tried it and it works with Option 0 = Projectile 1, Option 1 = Projectile 2, Min = 0 and Max = 1), but I don’t know how to connect Pickup Actor Blueprint with Index Pin of the Select. Is it possible?

Thats where you need the Branch. If there are only 2 options, you must conditionally determine the index using a branch.

Or you could simply use the Is Valid node. It ahs two execution output pins ‘Valid’ and ‘Not Valid’. You can use it instead of a Branch.

Assuming that you only have 2 projectile types, one used when pickup is alive and the otehr when it is destroyed. The follwing setup might work

[Is Valid] ------- (Valid)------>[Spawn Projectile(class='Projectile1')]

              ---- (Not Valid)--->[Spawn Projectile(class='Projectile2')]

I dont have my PC with me, otherwise I would have shown a working BP.

Now I am not sure why you are using a random node for this. Do you want to spawn a random projectile if pickup is dead?

The previous screenshot come from here: How do I use a random function? - Programming & Scripting - Epic Developer Community Forums I don’t want a Random node, but something like “Branch” or “IsValid” for switch from Option 0 to Option 1, but I don’t know how to connect “Branch” or “IsValid” with the Index Pin of the “Select”.

Anyway I think my real problem is connect the 2 BP: Pickup Actor and Spawn Projectile, something like “WHEN/IF Pickup Actor is destroyed/activated THEN Switch Spawn Projectile from 1 to 2”. Can you help me with this? I’ll come back on Monday…if you can, let me know.

Many thanks for your support!

If there are only 2 porjectiles available, there is no need for ‘Select’. I will show a BP later today

PS: To reply to an anser/comment, use the ‘Reply’ option under the post. Dont create new answers for that.

Here is how you should use the Branch.

What I did was to add a boolean variable in the character BP which will indicate if Pickup is active.

When you enter the pickup, it will set the variable ‘Pickup Active’ to TRUE. After 5 seconds, the pickup will self destroy and will set ‘Pickup Active’ to FALSE.

The branch inside character BP is used to spawn the correct projectile.

Pickup BP

Character BP

Many thanks Mindfane, I’ve tried with your BP and it’s perfect!
Thank you for your patience and support…Have a good day!