Change object color

-2

I want to change the color of the object through C ++ and not in the editor. I do this:

I set my two functions completely where I do it

 AWallActor::AWallActor()
{
    PrimaryActorTick.bCanEverTick = false;
    ProceduralMeshComponent = CreateDefaultSubobject<UProceduralMeshComponent>("WallMesh");
    ProceduralMeshComponent->bUseAsyncCooking = true;
    ProceduralMeshComponent->SetupAttachment(RootComponent);

    Material = CreateDefaultSubobject<UMaterial>(TEXT("Material"));
}
void AWallActor::BeginPlay()
{
    Super::BeginPlay();
    FColor WallColor(255, 0, 0, 255);
..............................................
    FColor WindowColor(255, 255, 0, 255);

    MeshSection Section;
    GenerateWall(Section, WallCenter, WallSize, WallColor,
        NumWindows, WindowFrameSize, WindowFrameWidth, WindowRailWidth,
        WindowLeftOffset, WindowTopOffset, DistBetweenWindows, WindowColor);
    ProceduralMeshComponent->SetMaterial(0, Material);
    ProceduralMeshComponent->CreateMeshSection(SectionIndex,
        Section.Vertices,
        Section.Triangles,
        Section.Normals,
        Section.UV0,
        Section.VertexColors,
        Section.Tangents,
        bCreateCollision);
}

Error:

ProceduralMeshComponent->SetMaterial(0, Material);


    Exception thrown at 0x00007FFED863BE95 (UE4Editor-CoreUObject.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000003B0000003F.

What is wrong. Why not change the color?

c++
unreal-engine4
asked on Stack Overflow Sep 12, 2019 by Olena Novitska • edited Sep 12, 2019 by Olena Novitska

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0