Lecture 84: Different code

In this lecture we were shown to use FindComponentByClass() to get the mass, but I did mine by using GetRootPrimitiveComponent() to the same effect. I found it by typing in PrimitiveComponent and it was the function that came up which had UPrimitiveComponent in the description.
Should I change it to what was done in the video? Not sure if there are side-effects I should be concerned about.

Nope, if it works, why worry, save’s a cast which is expensive.

1 Like

I didn’t think it would matter. There’s lots of ways to achieve the same result when it comes to programming, but I like to be sure when it comes to the best way to go about things.

I’ve tagged this with the lecture-specific code

wowser, it’s cool i’m not the only one who stumbled across that aswell.
To be fair I don’t even know what it technically means, root?, primitive?, why component? etc the quantity of procedures, features, technicalities and syntax seems overwhelming to me.

Ben, also want to confirm that I get the phantom drifting. And If I grab an object facing some angles, it propels the DefaultPawn_BP along with the ride… I thought it’d be one of those things that are just annoying enough but doesn’t stop us achieving our goal that it wouldn’t be addressed so it’s nice to see you comment (or quip!) about these niggling things.

thanks all.

GetRootPrimitiveComponent() has been deprecated and the recommended way to get this is:
((UPrimitiveComponent*)Actor->GetRootComponent())

Using a C-style cast isn’t recommended, if you want to use GetRootComponent, use UE4 casting

Cast<UPrimitiveComponent>(Actor->GetRootPrimitiveComponent());

I stand corrected, but I have never heard of UE4 casting.

It’s covered in BattleTank

Privacy & Terms