Hello,
After reading a lot and watching some videos, I’m happy to be having a smooth progression in UE4.
Still, there’s something that concerns me: I don’t like the idea of doing something because someone told me to do it, without understanding exactly what’s going on, so I decided to ask here.
I apologize if this is trivial for you guys, but this is so specific I’m having a hard time finding the magic search string to get a topic that explain to me what’s going on.
So, this is the most basic class, from what I understood from what I read:
UCLASS()
class HAVEN_API ABaseBarrel: public AActor
{
GENERATED_BODY()
public:
ABaseBarrel(const FObjectInitializer& ObjectInitializer);
/** Simple collision primitive to use as the root component. */
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Barrel)
USphereComponent* BaseCollisionComponent;
/** StaticMeshComponent to represent the pickup in the level */
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Barrel)
UStaticMeshComponent* BarrelMesh;
};
And, of course, it’s constructor:
ABaseBarrel::ABaseBarrel(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
// Create the root SphereComponent to handle the pickup's collision
BaseCollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("BaseSphereComponent"));
// Set the SphereComponent as the root component
RootComponent = BaseCollisionComponent;
//Create the static mesh component
BarrelMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("BarrelMesh"));
//Turn physics off for the static mesh
BarrelMesh->SetSimulatePhysics(false);
//Attach the StaticMeshComponent to the root component
BarrelMesh->AttachTo(RootComponent);
}
So, there are 2 questions I’d like to ask:
First question:
Why do I need a [FONT=Courier New]USphereComponent* BaseCollisionComponent ?
I mean, I’ll ultimately want to use a mesh collision, and I’d hate to have something think (example: a wood plank) with a small collision sphere in it’s middle. Is this really necessary?
Sadly, I don’t know how to visualize this kind of collider within the editor.
Plus, if this is actually what happens, there will be a bunch of extra collision stuff scattered across the level, which might not only lead to strange collisions, but might also be extra CPU time going to waste.
Second question:
According to the C++ tutorial video, I’d need a [FONT=Courier New]UStaticMeshComponent* BarrelMesh to hold my mesh.
That’s fine, until I had to do some math with it.
I noticed that every single actor out there has a [FONT=Courier New]StaticMesh component (that you change in the editor) and I couldn’t really edit [FONT=Courier New]BarrelMesh by itself, in the editor.
BUT the mesh position and rotation wasn’t linked to [FONT=Courier New]StaticMesh, it was linked to [FONT=Courier New]BarrelMesh! - I feel this is confusing.
Is that [FONT=Courier New]UStaticMeshComponent* BarrelMesh component required there? How would I proceed if I were to remove it and have my class without it?
I apologize in advance if these aren’t the best formulated questions you ever got, but I’m a bit confused with both elements in a basic class. I hope you can explain to me why these are needed and how to proceed if they are not.
Thank you in advance!