XaiJu
Megan Fox
Megan Fox

patreon


This is how, in Unreal, to tell if a pawn is local or not

I'm a bit behind on posts, so I'm just kicking this one out now, because I spent a very angry couple of hours and found no good explanations. Took a friendly person on a Discord.

Anyways, this is how to tell (in Unreal Blueprint but there's C++ analogs of the function) if any given actor is "local" to you, in a durable way. This will function regardless of whether you're in single-player, a client of a ListenServer, actually running AS a ListenServer, or a client connected to a dedicated server. This is how you ask "is this Character either my own character, or an AI character that is being controlled from the computer I'm sitting at."

The image shows it, but the gist is you get the controller, and use "IsLocalController". There's another version of IsLocalController if you specifically want to ask if this is the local Player (and ignore any AI that might also be local), but in my case I needed this to cover AI too, so there you go.

Where this comes up is, say for instance you're doing foot planting. Stick the feet down, in world space, when the animation says the feet are touching down. Really grounds your animations, cool tech, BUT, really bad stuff happens if your position skips around when the feet are planted. Because your feet only unplant when the animation lifts them back up. Which in a networked context won't happen, because you didn't actually move, the remote just replicated over the actual position of that thing, so it popped, and now its feet are stuck 60 feet from its body. If you're running IK, this will result in a dude glued to a spot, pointing with his whole body at the spot where he knows he should be. It's very silly, and catastrophic in a game that, for instance, ties hitboxes to the visible character mesh.

Annnyyywwaaaays, this fixes it, and now there's at least one google result that should pop up for this, hopefully. Because holy crap I looked at 5-10 and they were all either hilariously wrong, or didn't actually come up with an answer!

This also doesn't solve properly for the case of a Character that simply doesn't have a Controller. So don't do that. If I find a better solve for this that handles that case properly, I'll update this.

EDIT: Also, that Is Not Valid -> set as remote actor? That's critical. Because if you are a Client, and you are observing (from your end) the character of a ListenServer, it simply does not have a Controller on your end. Apparently. For reasons.

This is how, in Unreal, to tell if a pawn is local or not

More Creators