Is this more expensive or something game wise? I feel I rarely see people using functions in the tutorials they do.
If i am correct in my understanding, I need to create a function for whatever action I expect to need done automatically, put everything including the “Spacebar” trigger into that function, and then use the “cast to ThirdPersonCharacterBluePrint”. Then I add the function here.
The cost of using a function is so small, you may as well pretend it’s free.
As to what you “should” do, you’ll get a better feel for when to use a function as you go. I don’t think there’s any hard and fast rule about all actions needing to be separate functions, but I do think there’s a great benefit to separating your code out into small chunks that are easy to understand at a glance. Maybe I’m the weird one, though, because I’ll create a function where most tutorials will just wrap some nodes in a comments block. More than around 5 nodes feels like too much to me, except for basic math operations.
That said, your spacebar event is probably in the player controller. The pawn is where the actual jumping/animation would take place, so it makes sense (to me at least) to have the Jump functionality on the Pawn, and then the controller just calls like “GetPawn()->Jump()”
If you’re just starting out, though, it’s probably better to not overthink it. Do what makes sense to you… you’ll be the one that has to look at it again later if something goes wrong lol
Okay thanks. Just want to make sure I am understanding and following a decent practice. Also that way once I get to the point where I am understanding the engine decently I can provide beneficial help to others and return the favor.
You typically want to use functions for code you are planning on using multiple times, as a function only gets compiled once, no matter how many times you use it. If you were to simply copy the same nodes again, they would compile twice.
Now, I’m sure you can see how in a bigger project, where a single function might be used over 50-100 times, this can affect performance.