Download

How do I connect the input received in my PlayerController BP with my pawn's BP?

Hey guys,

I have a custom player controller blueprint accepting input and working as intended. Is there a kind of event or something I should be creating that the possessed pawn can receive? I don’t want to hard-code any functionality into the controller or the custom pawn class - I should be able to possess different pawns, and have them behave differently to the same input, if I so desire, rather than hacking away at the controller on a case-by-case basis.

How do I go about doing this?

Thanks,
HateDread.

you would need to check a diagram and see who intercept input event first. if you are aiming to have no input event at all, then interface would be your answer. but make sure your interface function only have inputs and no output. then in your controller, you can get controlled pawn, check interface implemented, and call the event regardless of pawn’s class.

There are 2 nodes called Enable/Disable Input… might work for you, you could disable input on all your pawns and enable on the one you want to control.

You should also have an interface that all types of pawn use.

Your controller should call the functions implemented in the interface (Action1, Action2 etc). Then you implement the actions on the different kinds of pawns.

That interests me… that interface idea. I’ve read about interfaces, but how do they fit in with the pawns? You’re saying the interfaces are like the potential actions either the player or AI can have, and therefore any controllers should be able to execute those? (Kinda like C++ polymorphism?) How do I know that every pawn in my game has the exact same potential actions? A bird is different to a spaceship or a bicycle.

It’s exactly like Polymorphism.

We won’t know if every pawn has the same potential actions… but that is the beauty of it, you don’t need to implement all actions on all your different pawns.

But if all your pawns have weapons… they can fire it… they can all move (probably)… So they have things in common, and should implement their own version of those functions.

I’m having trouble connecting via the interface. I have the following in my BP_PlayerController blueprint, where the functions on the right are part of the BPI_ControlFlight interface:

Interface:

And then the BP_BaseShip (i.e. my pawn) blueprint:

That breakpoint never triggers… am I connecting this the right way?

Thanks.

No, you’re not.

You interface has some functions… but your class is listening for events.

There should be some function names under “Interfaces” in you BP_BaseShip. Double click those and implement the functions.

I only have them in the area you describe when the interface’s functions have output variables? I didn’t think I needed any.

EDIT: This is what I see in BP_BaseShip when I have the interface added in the Blueprint Props section:

They just aren’t there.

Yeah, I have that problem too… I just make a dummy output on the function and wait for them to fix it.

What do you mean by ‘dummy output’?

Make an output on the function… and then not use it.

Okay, that fixes that.

Now when my BP_PlayerController calls the functions like in my first picture, it calls its own versions of them, not BP_BaseShip’s.

Uhm…

Both your controller and your Ship seems to implement the Interface, that’s not necessary. Only the ship.

Also, you need a reference to the ship to call it on… right now you are calling it on “Self” inside the controller… which means, it calls the function on the controller.

Thanks a lot! Finally got it working, and I understand blueprints a lot more. You’re a legend :slight_smile: