Beginner: Moving Objects


I’ve started to learn Unreal Engine and got stuck at a very basic point: moving objects. I do not unserstand the controller concept fully yet but I tried the following: I’ve got a single Cube Blueprint in my scene and scripted events for the key n and m pressed to add a relative position to the cube. The cube does not move. Why?


Is the cube a separate actor BP? Are these nodes inside that BP?

If yes, the input nodes won’t execute because there’s no controller possessing it. If you want to ‘remotely’ move it, you’ll have to cast to the cube via your character BP or whatever it is you are possessing. The easiest way of doing this is to spawn the cube via the character BP itself, using the node Spawn Actor from Class as this would give you a reference to that cube right away.

Another method is to use Get All Actors of Class, choose your Cube BP and then either loop through all the results or if you know there will only be one result, you can use the Get node with an index of 0. Since you’re getting all actors of a certain class, casting shouldn’t be necessary here.

I started with the First Person template, grabbed one of the cubes in the level, added a Blueprint to it and used the nodes seen above. The cube ist just an Actor, maybe it has to be a Pawn or Character or I have to add an controller component… To be honest, I don’t really understand your answer (my fault not yours…). What I think I understood is, that I need to have a controller, which collects the user input and transmit it to an Actor or Pawn. The rest about casting and spawning is out of my current range. The docs say, a controller can possess a pawn, but I really did not figure out, how. Maybe I have to look for a beginner tutorial about moving objects :slight_smile:

The concept of a controller processing the user input and routing it to the actors is a little hard to understand if coming from Unity as I do. In Unity it is as simple as that, checking mouse, keyboard or gamepad and move everything I like to move. I can use WASD to move player 1 and arrow keys to move 2 in a local multiplayer, a thing I have no idea to implement in Unreal.

Sorry for the delayed response!

Let’s say your cube BP is called BP_MyCube and you have your character BP_Character*(obviously it’s named something else in the FP template)*. If the cube exists in the world and you want to move it via using your keyboard, you first have to get a reference to it. We use this reference to manipulate that object, whether it is to move it, rotate it or call some function on that object. So how do we do that?

Method 1: Spawn the BP_MyCube via your BP_Character using the Spawn Actor from Class function*(for example from BeginPlay)*.

When you spawn an actor, you immediately get a reference to that object*(Return Value)*. Now you can drag this return value somewhere and you’ll get the option to promote it to a variable, go ahead and do so - then we can use this variable to access the object at will. For the sake of this example, let’s say you named the variable MyCube_Ref.

Now inside BP_Character you could repeat the code you provided above, but instead this time you do it like this;
N -> MyCube_Ref -> Add Relative Location.

I’m sure you know how to drag the variables to set/get them.

Method 2: If the cube is part of the map, you can get a reference to it via Get All Actors of Class*(change filter to BP_MyCube)*.

This function will return an array of objects which you can loop through. If you know there will be only one cube in the world, you can use the get node with an index of 0 instead of looping through the array. Once you’ve got the reference to the cube, you repeat the same as above.

Again do note here that the input is handled via BP_Character since it will register input, BP_MyCube will not as it’s just an actor.

Hopefully this was a bit more explanatory :slight_smile:

This could also be achieved in UE4 simply by using the GetPlayerController node, player 1 will have the index 0 and player 2 will have index 1 and so on.

Unfortunately multiplayer in UE4 is a bit convoluted*(but powerful)* when compared to other engines and not very well documented yet. All they really tell us is how to click a checkbox to enable replicating and using the authority node. They do a really, really bad job at explaining and showing how to set up a MP testing environment that accurately produce the same results you would get in a packaged game*(I have yet to figure this out, closest I’ve got is to just package the game and run it on my laptop, have not yet found an environment that works in UE4 Editor)*.

Hi Dealman,

thanks for coming back :slight_smile:
I think I understand your description a lot better now. I was not aware of the fact, that the movement of the cube must be programmed in the character blueprint. With this in mind I can get a picture of your two solutions and surely I will try it.
But: What about a completely blank map made of no given template. Just a cube blueprint in empty space. How can I move it by keyboard? Can it get a controller component for it’s own? Do I have to create that cube blueprint from “Pawn” or “Character” instead of “Actor” so he gets the needed components?

Yeah you can move static meshes, you just need to get a reference to it and cast to “StaticMeshActor”(if it’s just a static mesh you dropped onto the level and not a BP of some sort) and you’ll get a reference to that mesh and be able to move it. Personally I would probably use linetracing for this, though.

This is how I would go about for a basic test;