Having problems when possessing characters

i am trying to make a feature where i can possess the closest character to me when i hold down the right mouse button but i am having problems. i am not sure what is wrong. please help.

The above blueprint will not work because you are never calling Get All Actors of Class. Notice that the input arrow on that node does not have a line connected to it, so it will never execute. Try putting Get All Actors of Class between the Right Mouse Button node and Possess node, then it might work.

i have changed my code but it still doesn’t work.

Is this a single player or multiplayer game?

single player

ok, it looks like on release of the right mouse button you are possessing the original character. Is this what you want? Is this system only supposed to possess the other character while the right mouse button is held down?

yes the character should only be possessed whilst the right mouse button is held down

ok, put a breakpoint on the Possess node after the Set Closest Actor node and then check the value of Closest Actor. Also, it looks like there is a logic error in your For Each Loop. You set a variable called Nearest, but then you never use it. Instead you are always just selecting the last character in the list. You may want to Use Nearest as the input to the Set Closest Actor node.

what is a breakpoint?

Breakpoints are the cornerstone of debugging in UE4 blueprints. They allow you stop the execution of the blueprint and observe that values of certain variables at the time execution was halted. For your case, right click on the Possess node after the Set Closest Actor node and then click on Toggle Breakpoint. A red circle will show up on the node. Then run your game and click the right mouse button to execute that section of code. When it hits the breakpoint, your game will stop and you will be able to see the value of Closest Actor by putting your cursor over the Set Closest Actor Node. This will tell us two important things. First it will tell us that it got to the Possess Node. You would be surprised how many times a BP doesn’t work because it doesn’t even try to run the code you think it is running. Second it will tell us which Character you are going to try to Possess. A possible issue with your BP is that there are no character to possess, in which case the Possess node isn’t going to possess anything.

what does this mean?

That is a good sign. It means that your code is getting to the Possess node. Now you want to hover over either the In Pawn pin on the Possess node or the input pin on the Set Closest Actor node and see which actor you are trying to possess.

it says pawn to be possessed current value = none

There you go. There is the problem. A possible reason is that no Characters were within the minimum distance you setup. What distance did you use for minimum distance?

it is 5000

ok, so that is 50 meters. Make sure there are other objects of type Character or inherited from Character within 50 meters when you press the right mouse button. At least now you know what isn’t working in your code. Now you just have to figure out why.