How to spawn in the air


with my code is possible to spawn only in the floor or other objects, but how to spawn in the air? So if clicked above from floor I want to spawn above where click on the mouse cursor?


The line trace returns the hit location, which is the world location of the hit. A location vector has 3 components, ‘X’, ‘Y’, and ‘Z’. In Unreal the ‘Z’ axis represents the ‘height’, so you will need to either replace the value of the ‘Z’ component with a constant value, or you can also add to it.

Something like this, in this case the Actor will spawn ‘1000.0’ units above the object that the trace hit:


not works, maybe is problem get mouse position?

That seems a bit convoluted to me, PlayerController actually has a function called ‘ConvertMouseLocationToWorldSpace’ that will directly give you the world location of the mouse.

Something like this (if you are not using a top-down perspective, you might want to offset something else than the MouseZ for the trace, or if you have an in-game screenshot about what you are trying to achieve that would also help giving a more precise solution):

thanks for that!