Okay, I’m stumbling along, following tutorials trying to learn and I decided I wanted the ability to switch out player Characters which was easy enough to figure out. What I can’t figure out is how to make the Interactions ( Doors, collectibles) work with whatever character I throw at it. The problem is calls to Cast ToBP_MyCharacter in various places.
I have an interface set up per a tutorial that didn’t go into any detail about how to actually apply it to existing code.
I’ve also tried creating a Player Controller and putting everything in the controller. I still need to fix the casting issue in other classes for that to work.
Thinking about it, I’m thinking about the feasibility of creating a Base Player class, put all the variables (Instance edible) in it and then have it be the parent of my Players. Is this a viable approach? If I cast to MyBasePlayer, would it return the active Child’s variables or is their a way to get the active child’s variables?
If anybody can point me to any applicable tutorials or documentation that’s applicable, I’d appreciate. Most of the tutorials I’ve found go into great detail about what an Interface is and why you should use one, even how to set them up. Very little on actually integrating them into a project. The one detailed explanation I found was for c++, I’m all blueprints at this point.
Below is what’s in one of my collectables. I’ve got it set up to use an interface, the unused event on interact (from the interface) is supposed to do away with casting. How should I go about implementing it? Any help is appreciated.
Most of the time collectibles do not need to know who or what it is interactiing with. They are meant to exists until told to be destroyed.
The logic to handle what happends to the collectible actor can be placed in an actor component applied to the possessed pawn with a bind to the owners overlap event. This component can handle the cast to the base collectible class and get what ever it needs. Tags can also be used to further filter the collectibles and execute more logic if needed.
Interfaces could be used over casting to the base class, but IMO it depends.
Same somewhat applies to interactive props, but here interfaces are usually needed to decouple the classes. From the point of view of the possessed pawn, when E is pressed the pawn traces and tries to call the interface on what ever it hits. If the actor being hit has the interface then it will execute an event. Neither needs to know who / what / etc…
This will allow you to set basic functionality in the base class and overrite in the child classes for added functionality.
So you can have a base class (a door) that has an event that changes the states opens / closes; a child can overrite the event to only trigger when a possessed pawn is overlapping or < X distance and another child that will only trigger if a specific component was hit. Maybe a door has to check if certain number of items have been collected or another won’t open if the player has certain item… etc
The main point of all this is to have as much as possible be event driven.
In this specific case I suggest you remove all this from the coin class. Add an actor component to your pawn that is able to detect if it overlaps a coin, if it did then destroy it on overlap and do the rest.
Thank you for your reply. I’ll take a look at stack o bot to see how they do it. I guess what’s got me confused is don’t I still have to reference the player at some point? Even the OnInteract event has a target player.