Hello Unreal Engine enthusiasts,
I am relatively new to game programming and previously I was learning Unity3D to understand some basics.
In Unity3D I tend to structure my Character code in a modular kind of way, where each mechanics is a different script\component (e.g.: sprint, wall jump, shoot, and e.t.c.) that is added to the character Object and then accessed with a GetCompoent(“Sprint”) function, assuming “Sprint” is added to the object.
In UE4 I see there are various types of Components that I can create using C++ code, but I’ve been struggling to understand the correct workflow using multiple components to implement different mechanics for the Character.
Can anybody help me with some simple code examples please?
Here is some basic workflow that I am intended to use:
- Lets say there is a component “Sprint” that has a function “OnSprint()” that should be called by the “MainCharacter” class
- “MainCharacter” would then get reference (?) to each of the “Sprint” Component and call “OnSprint()” when needed.
- How do I get this reference? Do I use GetComponents() function and loop through the array to find “Sprint”? Or is there a better way to do that.
- Is there a better\different workflow to accomplish that?
Thanks.