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.
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.
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,
.
[/QUOTE]
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.
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.
[/QUOTE]
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?
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.