// Fill out your copyright notice in the Description page of Project Settings. // Sets default values #include "AgeTestingGrounds/Public/ColoredCube.h" #include "Materials/MaterialInstanceDynamic.h" #include "Materials/MaterialInterface.h" #include "Components/StaticMeshComponent.h" AColoredCube::AColoredCube() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; } // Called when the game starts or when spawned void AColoredCube::BeginPlay() { Super::BeginPlay(); auto Cube = FindComponentByClass(); auto Material = Cube->GetMaterial(0); DynamicMaterial = UMaterialInstanceDynamic::Create(Material, NULL); Cube->SetMaterial(0, DynamicMaterial); } // Called every frame void AColoredCube::Tick(float DeltaTime) { Super::Tick(DeltaTime); float Blend = .05f + FMath::Cos(GetWorld()->TimeSeconds/2); DynamicMaterial->SetScalarParameterValue(TEXT("Blend"), Blend); }