Download

Need help with spawning AI at mouse location

So far I have this

And forgive me if my blueprints are completely wrong as I am trying to learn, but this kinda works. It spawns at my camera location and not where my mouse location is when I click the button.

I am using Engine 4.6 and the top-down template. I am trying to get a spawn like in a RTS game where you would press a UMG button and then point and click to spawn an AI.

Any help would be appreciated.

Thanks!

I sent you a PM but I’ll explain a bit here. In your widget blueprint, select the UMG button you want to use. On the right, scroll down until you see “Events” and click on the OnClicked event. That’ll take you to the graph and add the event. Now from there you want to get your mouse location. To do that use “GetPlayerController” and use that return value to “GetHitResultUnderCursorByChannel”
You’ll break the hit result and you’re going to want to use “Location” or “ImpactPoint”
To be honest, I don’t know what the difference is. Both of those usually give a pretty good idea of where in the 3D world your mouse is. Use that location as the spawn point for your AI. Now if you do that, it’ll spawn right under the UMG button because that’s where your mouse is at the time. My suggestion is use EventTick to set the newly spawned AI’s location to that cursor location you got. Then with a click (left or right, up to you) have a DoOnce that will stop setting the new unit’s location. You can use a Gate for that. Here is a picture of what I’m talking about:

This is a very simple way of doing it but it definitely works.

Let me know if that helps at all.

Yes that actually helped a lot Thank you very much!