Hi, I am beginner. I am trying to set the static mesh based on the data table. I finished it, but I can’t see static mesh’s details part. Also, I am trying to set collision, but nothing happens. I will send code in the comment part. Any idea?
AGridModifier::AGridModifier()
{
PrimaryActorTick.bCanEverTick = true;
USceneComponent* DefaultSceneComponent = CreateDefaultSubobject(TEXT(“DefaultSceneComponent”));
SetRootComponent(DefaultSceneComponent);
StaticMesh = CreateDefaultSubobject(TEXT(“StaticMesh”));
StaticMesh->SetMobility(EComponentMobility::Movable);
StaticMesh->SetupAttachment(GetRootComponent());
Tags.Add(“GridModifier”);
}
void AGridModifier::BeginPlay()
{
Super::BeginPlay();
// I am not sure about this code, but it doesn’t work even if I delete them
StaticMesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
StaticMesh->SetCollisionObjectType(ECC_EngineTraceChannel1);
StaticMesh->SetCollisionResponseToChannel(ECollisionChannel::ECC_EngineTraceChannel3, ECollisionResponse::ECR_Block);
}
void AGridModifier::OnConstruction(const FTransform& Transform)
{
if (!DataTable || Shape == EGridShape::None) return;
FGridInfo* CurrentRow = UGridUtility::FindCurrentRow(DataTable, Shape);
UStaticMesh* Mesh = CurrentRow->Mesh;
if (Mesh) StaticMesh->SetStaticMesh(Mesh);
if (NoneMaterial && NormalMaterial && ObstacleMaterial)
{
UMaterialInterface* CurrentMaterial;
switch (TileType)
{
case ETileType::None:
CurrentMaterial = NoneMaterial;
break;
case ETileType::Normal:
CurrentMaterial = NormalMaterial;
break;
case ETileType::Obstacle:
CurrentMaterial = ObstacleMaterial;
break;
default:
return;
}
StaticMesh->SetMaterial(0, CurrentMaterial);
}
}
If anyone have the same problem, be sure to make your static mesh component UPROPERTY in code.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.