In the CharJumpComponent example, Mathew uses a casting in order to access an event dispatcher of his Character (Char_ActorComponent). Although this works good it's not implemented in an "agnostic" way, meaning that CharJumpComponent will only work with Char_ActorComponent and will also have a dependency with it. IMO when using components it's always good to do it in an agnostic way so we can use this component in many different Actors, ofc it's not always possible but in this case we could use Interfaces. We could create an interface that has two methods: JumpEvent and JumpStopEvent, make the CharJumpComponent implement this interface, and call this interface from "Char_ActorComponent" using the CharJumpComponent reference (in this case, the node "isValid" should be used before the call). And in the case the game needs to replace "CharJumpComponent " with a different component (let's imagine that it's a "CharFlyComponent") in order to change the Character behavior, that's pretty easy. We just need to use an ActorComponent reference to hold either a CharJumpComponent or a CharFlyComponent depending on the situation. Since we're using interfaces, JumpEvent and JumpStopEvent will still be accesible from an ActorComponent reference. Of course, in this example maybe we would need to change the name of JumpEvent and JumpStopEvent to make it more "agnostic" to both Jump and Fly functionality.
I also had the exact same thoughts. the method up there is cool , but not agnostic. Your Approach is better, at least as long one stays inside blueprint-world. thanks
I'm afraid I don't understand. If we were to not use casting, how can we get access to player's "jump" function in component? I can't do it via "Get owner"...
The bad thing with Unreal Engine though, is that if you put this interface on an actor component in order to extend the behavior of an actor, you can't just call the interface on the actor because it won't be passed on. You must know that the actor has a component that implements the interface and search for it explicitly, which is rather tedious.
Mathew dude thank you for presenting some actual use cases. Watching this particular video has now finally given me the answer to my problem and I should now be able to create my dream game. Many thanks.
Another way to do this, and probably the simplest way if I'm not mistaken, is to have the jump input event in the character BP directly call the jump event in the component. So in "Char_ActorComponent" have an "InputAction Jump" node which calls CharJumpComponent's "jump" event, and performs an action on its owner. You could then also have, for example, an NPC which calls its own jump component's jump event, as a result of AI commands or whatever (as opposed to player input). This is how I'm handling weapons in my game. The player tries to shoot, player BP checks if they are capable of shooting, then it asks the current weapon component to run its "shoot" event, which performs whatever action that particular weapon does. NPCs can call the same shoot event from the same weapons, but they also run different code on their own end because they don't need to perform all of the same checks a player's bp would (e.g. hitreg/lag compensation etc).
My game will have a fixed-camera point and click style. If I have "NPC" characters that will walk around and are clickable they will have a lot of events and functions like showing a nametag and highlighting themselves with a post-process outline effect when I mouse-over. The NPC blueprint will be based on the "Character" class which is derivative of the "Actor" class. If I want to add a new type of blueprint, let's call it "Interactable", for static objects like doors and treasure chests they will have most of the same features that I created for NPC for interaction but they should be based on the "Actor" class because they don't need all of the features supplied by the "Character" class like movement, collision, navigation and AI. So my question was how do I share events, functions, and variable setup between the two classes in a way that won't force me to edit multiple blueprints exactly the same way in my project every time I add a new game system or fix a bug on these classes? I don't want to make my NPC class a child of the Interactable if it means I have to recreate all of the Pawn and Character functionality myself. The answer is Actor Components! All I need to create is a new Actor Component called something like InteractableComponent and put all my functionality in there, then I can just drop this component in any actor I want and now the component has a context in which it can do all kinds of things :D
Hi Mathew WTF is attach actor to component node HTF do i use the bool value to call the attachment condition without actually using the execution of the attachment between the two as if i already called the ATC node in a macro and now just wanna know HTF to call thay event without attaching again
I am struggling on understanding when you should use a component versus an interface. They seem very related. What would be the advantage of using a component over an interface?
I want to be able to spawn buildings. All the logic should be handled by the individual buildings (enough Money, free space…). Should I use an component or an „Master“ and Child BP? Also I need to store some information about the building (costs, Building Type…) Should this be another component or part of an Master BP of wich every building is a Child of?
Mathew thanks for the videos great stuff, but for instance if I was making a hierarchy of weapons would it be a component or an actor? A weapon would be part of the player actor? Even after watching still a little confused.
Assertion failed: AttachedActor->ParentComponent->GetOwner() == this [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/Engine/Private/ActorConstruction.cpp] [Line: 391] BP_EnemyShip_Parent_Child_Child . I made a copy of the original BP_EnemyShip. Then from that copy I made a child component, I edited that. Now on the third asset created which is BP_EnemyShip_Parent_Child_Child the copy of the copy i get the error mentioned above. Im looking for a solution dont know where to start. I have a Capital ship and attached turrets as children.
You are BY FAR the most detailed teacher on UE4.
Thank you for making all these videos.
XD he is by far the worst
Your tutorials are very quality but the tomatoes in your intro bring Suicidal Thoughts to my dreams.
In the CharJumpComponent example, Mathew uses a casting in order to access an event dispatcher of his Character (Char_ActorComponent). Although this works good it's not implemented in an "agnostic" way, meaning that CharJumpComponent will only work with Char_ActorComponent and will also have a dependency with it.
IMO when using components it's always good to do it in an agnostic way so we can use this component in many different Actors, ofc it's not always possible but in this case we could use Interfaces. We could create an interface that has two methods: JumpEvent and JumpStopEvent, make the CharJumpComponent implement this interface, and call this interface from "Char_ActorComponent" using the CharJumpComponent reference (in this case, the node "isValid" should be used before the call). And in the case the game needs to replace "CharJumpComponent " with a different component (let's imagine that it's a "CharFlyComponent") in order to change the Character behavior, that's pretty easy. We just need to use an ActorComponent reference to hold either a CharJumpComponent or a CharFlyComponent depending on the situation. Since we're using interfaces, JumpEvent and JumpStopEvent will still be accesible from an ActorComponent reference. Of course, in this example maybe we would need to change the name of JumpEvent and JumpStopEvent to make it more "agnostic" to both Jump and Fly functionality.
I also had the exact same thoughts. the method up there is cool , but not agnostic. Your Approach is better, at least as long one stays inside blueprint-world. thanks
I'm afraid I don't understand. If we were to not use casting, how can we get access to player's "jump" function in component? I can't do it via "Get owner"...
@@Dogmen58 Look up blueprint interfaces they are amazing
The bad thing with Unreal Engine though, is that if you put this interface on an actor component in order to extend the behavior of an actor, you can't just call the interface on the actor because it won't be passed on. You must know that the actor has a component that implements the interface and search for it explicitly, which is rather tedious.
These have been some very helpful tutorials, man. Well done.
Great Video! The input part reminds me about how the new enhanced input works 🤔
Mathew dude thank you for presenting some actual use cases. Watching this particular video has now finally given me the answer to my problem and I should now be able to create my dream game. Many thanks.
Your tutorials help me so much.
... Extremely useful. It just opened my mind to so many possibilities and approaches thou...
... Thanks a lot .... : ),,
Another way to do this, and probably the simplest way if I'm not mistaken, is to have the jump input event in the character BP directly call the jump event in the component. So in "Char_ActorComponent" have an "InputAction Jump" node which calls CharJumpComponent's "jump" event, and performs an action on its owner. You could then also have, for example, an NPC which calls its own jump component's jump event, as a result of AI commands or whatever (as opposed to player input).
This is how I'm handling weapons in my game. The player tries to shoot, player BP checks if they are capable of shooting, then it asks the current weapon component to run its "shoot" event, which performs whatever action that particular weapon does. NPCs can call the same shoot event from the same weapons, but they also run different code on their own end because they don't need to perform all of the same checks a player's bp would (e.g. hitreg/lag compensation etc).
My game will have a fixed-camera point and click style. If I have "NPC" characters that will walk around and are clickable they will have a lot of events and functions like showing a nametag and highlighting themselves with a post-process outline effect when I mouse-over. The NPC blueprint will be based on the "Character" class which is derivative of the "Actor" class. If I want to add a new type of blueprint, let's call it "Interactable", for static objects like doors and treasure chests they will have most of the same features that I created for NPC for interaction but they should be based on the "Actor" class because they don't need all of the features supplied by the "Character" class like movement, collision, navigation and AI.
So my question was how do I share events, functions, and variable setup between the two classes in a way that won't force me to edit multiple blueprints exactly the same way in my project every time I add a new game system or fix a bug on these classes? I don't want to make my NPC class a child of the Interactable if it means I have to recreate all of the Pawn and Character functionality myself.
The answer is Actor Components! All I need to create is a new Actor Component called something like InteractableComponent and put all my functionality in there, then I can just drop this component in any actor I want and now the component has a context in which it can do all kinds of things :D
Mathew, your videos are a godsend. Thank you so much! :D
Thank you God for such a great ppl like Mathew
Thank you,
What is the equivalent of dummy in maya or empty in blender?
Engaging and relevant, I feel like I Have gotten answers!
Amazing work man, keep it up!
I could have sworn you had already done this
Hi Mathew WTF is attach actor to component node HTF do i use the bool value to call the attachment condition without actually using the execution of the attachment between the two as if i already called the ATC node in a macro and now just wanna know HTF to call thay event without attaching again
I am struggling on understanding when you should use a component versus an interface. They seem very related. What would be the advantage of using a component over an interface?
I want to be able to spawn buildings. All the logic should be handled by the individual buildings (enough Money, free space…). Should I use an component or an „Master“ and Child BP? Also I need to store some information about the building (costs, Building Type…) Should this be another component or part of an Master BP of wich every building is a Child of?
Love this chanel!
Mathew thanks for the videos great stuff, but for instance if I was making a hierarchy of weapons would it be a component or an actor? A weapon would be part of the player actor? Even after watching still a little confused.
You're a legend
If I add a custom actor component it will crash my editor if I set a breakpoint in it, even if it's blank.
Assertion failed: AttachedActor->ParentComponent->GetOwner() == this [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/Engine/Private/ActorConstruction.cpp] [Line: 391]
BP_EnemyShip_Parent_Child_Child . I made a copy of the original BP_EnemyShip. Then from that copy I made a child component, I edited that. Now on the third asset created which is BP_EnemyShip_Parent_Child_Child the copy of the copy i get the error mentioned above.
Im looking for a solution dont know where to start.
I have a Capital ship and attached turrets as children.
A bit late but Wtf is? Scene components?