Spawning actor component when button pressed

Hi,

What I have so far is a wind spell created as an actor blueprint and i have placed it into my pawn as a ‘child actor component’ where i would want it to be.

What i now need to do is for the ‘child actor component’ (windspell) to be destroyed when starting the game and to appear when a controller trigger is holding. So when the trigger is holding the ‘child actor component’ appears where i placed in my pawns view port and when the trigger is no pressed to be destroyed.

I would want it to work as a flamethrower mechanic for example so its constantly spawned when a button is pressed.

Sorry i am still a beginner with blueprints so if I missed anything please let me know :slight_smile:

Thanks in advance!!

Tadas

Is your idea to spawn this actor component only when youre holding down the button, and then check for collisions/overlaps on it? Another way to do it might be to spawn a particle when they push the button, and it destroys the particle when they release the button. And while the button is pressed you can do a boxtrace (https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseRaycasts/Blueprints/#shapetraces) for anything inside of it.

Currently i have a wind spell setup as a projectile and got it set up in my pawn for the projectile to be spawned into the world and shot from where ever i referenced, currently its being shot as a gun while holding.

I need to make it constantly appear not shoot when the button is holding and stay locked to my pawns hand so when it overlaps an enemy AI the effect of the knockback is activated.

I have included my blueprint for the projectile and a screenshot of the pawn

okay I think I understand a little bit better. So one thing you could do is instead of repeatedly spawning it every .35 seconds, you can spawn it once. And in your update function, you can check if right trigger is pressed, and if it is, move the projectile to where it should be (your hand) and check for collisions. Then when you release right mouse you can destroy it. Sorry I’m at work so I don’t have UE4 open or id make a mock up but did that make sense?

It now stays in the scene when pressed and does destroy it self when the button is not pressed, so now i need to lock the projectile to my motion controller when its in the scene.

I’ve gotten this far and not sure what nodes to use to make use to make it constantly check where my motion controller is in the scene.

Ive attached a screenshot of how far i have gotten

Thanks

Awesome, that’s exactly what I meant. So I see where you’re trying to make it constantly check at the end there. What you want to do, is your blueprint should have a node that’s called “Event Tick”. And what that does is every game loop, it calls that function. So in there is where you can check if the button is pressed, and if it is, move the actor to where your controller is.

What node would i use from true that would allow me to move the actor where ever the controller moves?

So when you create the wind actor, you’d want to store that in a variable. And then you would set the position of that variable (the actor) to where the controller moves.

I’m not sure how to how to make the variable of the actor when its spawned, but if you meant to make the variable type as my spell then I’ve got that in. what node would i use to plug in my ‘GetWorldTrandsform’ into to attach it to the controller?

sorry i am still learner :slight_smile:

here is an updated screenshot of how it looks now.

Okay cool. So what I mean is, when you spawn the actor with the “SpawnActor Wind Spell” block, you want to store that return value in a variable using the variable setter. And then, when you destroy the actor, you want to use the getter for that same variable. In your event tick function, you want to then move the location of that actor to be where the location of your character is.

okay I see what you mean with storing the variable, it’s a vr project so i need to attach it to a component inside my pawn because that’s where the controller will be so i need it track the location of my controller inside the scene and transform the location of the spell so its constantly attached.

would you know the exact nodes that i need to use?

here is an updated screenshot

thanks

Try putting the return value from GetWorldTransform into the goal location parameter on your move to actor or location and see if that works. For your event tick, before you call the Move to location or actor function, you want to make sure left trigger is pressed.

Get world transform did not work but i was able to use get world location.

Now it requires a controller in order for the blueprint to compile, it lets me get AiController but does not let me use the controller that the player pawn is under.

thanks

updated screenshot

Try using a “Set world location” node instead of the one you are using, and you won’t need the controller. Pass in the wind spell actor as the target and the world location of where you want it to be as the new location

Awesome that worked! Now when the the actor is spawned it tracks the hands movement but it is locked on an axis and if I turn my hand the actor doesnt

Nice! so then do the same thing you did for set location, but use a SetActorRotation node, with the spell being the target and the new rotation being the rotation of the controller thing.

Awesome!! finally done :)! thank you so much for putting up with my blueprint abilities haha! thanks for such fast answers aswell!! got exactly what I wanted to!

Awesome! I’m glad we could get it working