Raising an actor by clicking directly on it and holding mouse button

I have managed, however inelegantly, to create a blueprint that allows me to raise a block (blueprint).

Now if I have one of these blocks I can raise it (and I’ve done a lower function as well, pretty much the same).

I have two issues:

  1. It doesn’t matter where I click on the gameplay screen, the block raises regardless. I only want to raise the block I am clicking on.

  2. If I create a second block, wherever I click on the screen only one block moves, and it still doesn’t matter if I click on a block or not.

Here’s the construction script:

17356-problem3.png

Here’s the Event Graph section for raising the block:

And here’s the Raise Ground Function:

What I’d ideally like to do is raise/lower any particular block whilst I’m clicking on it.

As a bonus, my goal is to have 25 of these blocks and when I click on the centre one it raises that one, then raises the surrounding blocks at a slower rate, and the blocks surrounding those raising at an even slower rate. Then I want to use the middle mouse button (or any other) to bring all the blocks surrounding the block clicked on into line whether raised or lowered.

I’m missing something key. Number 1 above is the priority. Still, any assistance would be appreciated.

Hey -

In your event graph for the raising of the block, you’ll need to add a “Get Player Controller” node and wire off of that to a “Set Enable Mouse Over Events”. You can then wire the input execution pin into your InputAction node. This will give you the behavior of only affecting the box when the mouse is held down while over it. This should also prevent any other boxes from reacting to the mouse input without the mouse overlapping them.

Cheers

Hi ,

Thanks for the answer. Do you mean like this? This didn’t have any effect. Am I missing something?

17368-problem_res1.png

Rather than using your InputAction to set Enable Mouse Over Events, try using an Event Beging Play. This will allow for mouse over events from the start of the game. Then use an Actor Begin Cursor Over event to set a bool that checks if the mouse is over the object (and and End Cursor Over to reset when the mouse moves away). Using an Event Tick to first check the bool for if the mouse is over the object and if that is true, do another check if the mouse is held down. This can then be wired into whatever drives the movement of your actor.

OK, I get what you’re saying. This is how I built it:

However when debugging I never see any output from the Event Actor Begin Cursor Over or Event Actor End Cursor Over. It’s like it didn’t detect the mouse was over the object.

The pressing of the left and right mouse button still set appropriately, and the End Tick is pulsing away, but since it relies on the Mouseoverobject bool that never gets set nothing moves on from there.

I can’t help but be feeling a bit stupid now. I know the logic in my head but I just can’t get the blueprints to do it. I have to admit I wasn’t in favour of using Event Tick at all as from what I understand it relies on clock cycles and can have adverse performance on a game if the CPU is overloaded. Still, I’ll go with whatever advice I can get.

Oh, just below the Branches coming out from Event Tick the condition bools are Mouseoverobject for the first and Mouse Held Down for the second.

Hey -

A Set Show Mouse Cursor node will unlock the mouse from the viewport and still allow it to interact with the scene. This along with the enable mouse over events wired to a Begin Play will let you move the mouse around and click on objects in the level. The Tick event will allow for the game to check each frame is the mouse button is still held down and will give a more fluid animation for the movement.

Check out this setup to help get started:

Hi . Thank you for your help.

I have one problem - my game mode is to already have the mouse cursor enabled, but even on changing that I cannot find a way to create the SET Show Mouse Cursor with a target. It doesn’t seem to be on the list of available commands.

Any thoughts?

It should appear in your context sensitive menu if you pull off of the return pin from Get Player Controller.

OK, here is now how the layout has been done, and is running. I now have detection of mouse over the object, but the left-click of the mouse is not detected so nothing ever moves.

OK, I’ve gone one step further with the whole plan, but it doesn’t change much.

I have now created the following (yes, it’s messy, but I’ll tidy it down into functions once I see the debugging lines show me it’s all working).

The following is designed to create 9 of the blocks previously referenced (it goes on further to the right creating all 9 blocks. However, I cannot reference any of the generated blocks or interact with them.

In this case, I’m not even receiving a mouse-over event, let alone a mouse-click event. Any idea, please please please. I’m getting so close to getting a core mechanic sorted out and this is now SO frustrating.

Oh, for reference the last image I posted was from the level blueprint.

Hey -

The setup you have in the “nomousehelddown.png” is actually very close to what you’re looking for. By adding a “Get Player Controller” node you can drag off of the return pin to add both the “Set Show Mouse Cursor” and “Set Enable Mouse Over Events” nodes as needed. Below is another image of mostly the same nodes from your image (I did use a Set Relative Location rather than Set Actor Relative Location) plus the nodes for showing the mouse and enabling mouse overlap events in the top right.

OK, daft question, but one I frequently come up against and every time I miss the answer I bang my head on the wall.

You’ve added a Set Relative Location for the Target being the RaisingActor_C (StaticMesh1) but all I can get is the target being SceneComponent. How did you get it there?

Is it something to do with the fact that I’m generating the objects in the Level Blueprint at the beginning, so it isn’t an object listed in the Scene Outliner…so I’m not sure where i’m going - I know it’s basic, I know I saw it in a tutorial, but given the number of tutorials I’ve been through I’m not sure how I’d find that specific requirement. I’ll research and give the answer if I find it.

Oh, I should mention that the problem isn’t getting to the Set Relative Location stage.

The problem is that I’m not even getting recognition of the mouse being over any of the spawned objects, nor an instance of the object that I put into the project manually.

The rest of my graph is pretty much the same as you’ve put in, but I never see anything when debugging that shows the MouseIsOver boolean variable ever going to Yes.

Based on the last image you sent of the blueprint that controls the actor, the node that enables mouse over events is missing. If you add a “Get Player Controller” node you can drag off of it to then create both the “Set Show Mouse Cursor” and the “Set Enable Mouse Over Events” node. Wiring them into an event such as begin play or another key press will show the mouse and allow it to register the Actor Begin Cursor Over node which should trigger the mouse over events.

If you post an image of what your actor blueprint looks like it will help determine how to edit it properly.

Cheers