How to add mesh to level at runtime using blueprint

Hi:

I want make a featue: place a static mesh(eg: a box) where the mouse click. I can make many boxes by mouse clicking.

How to build this feature in blueprint editor?

Thanks bro.

create a player controller blueprint

  • go to class default settings and under mouse interface enable “show mouse cursor”

create a game mode blueprint

  • go to class defaults and assign the player controller you just created as the Player Controller Class

create a blueprint for the mesh you want to spawn

  • many classes would work. Actor with static mesh component, or StaticMeshActor are fine. Either way, select the static mesh in the components panel and in the details panel select your desired mesh.

In the player controller blueprint again, create an event for the left mouse button.

  • on pressed, use the node “Spawn Actor from Class” and select your blueprint
  • to get the transform, use the node “Get Hit Result Under Cursor by Channel”
  • break the hit result
  • make a transform from the location