Recently I’ve been trying to learn different areas of the engine and was wondering if it was possible to convert this blueprint template to C++.
Any links to articles or whatever that cover this would be appreciated.
Thanks in advance!
Recently I’ve been trying to learn different areas of the engine and was wondering if it was possible to convert this blueprint template to C++.
Thanks in advance!
some things work better in C++ (better performance, more strict dependencies, and closer to single execution assembly after compile)
there are some things that actually do worse in C++:
Most of these boil down to “specific references should live in blueprints” otherwise we get into “Runtime resolved Hard References” (these have a bunch of problems for more detailed reading StaticLoad problems - failing to find file - #2 by anonymous_user_4fe9f58b1)
for things with timelines the biggest reason to do these in blueprints is you get a graph with points you can move around on that graph, and maybe even modify curve slope. the alternative in C++ is manually managing state through some kind of enum/int, and then making functions of (float deltaT). and probably involving Tick (it is mostly blueprints that gives Tick the bad name, but Tick is not the problem directly)
for this specific situation if you want to move forward moving it into C++ an implementation would be have a state variable (enum or int) then in Tick()
check the state variable and do your modifications to what I am presuming is the transform.
where the slope is Linear then you have a bit of luck where FMath::Lerp()
is already defined (there are defined flavors of Slerp as well but those are more specific)
the signature on Lerp might be intimidating but
FVector NewLocation = FMath::Lerp(GetLocation(), TargetLocation(), DeltaTime);
though this might require a check for if you have arrived at the destination with a “more meaningful” (GetLocation() == TargetLocation)
if you want parabolic behavior (easing) you might consider like FMath::VInterpTo()
.