I’m currently working on a small game idea that involves shooting projectiles that change color when they hit a wall.
I’m doing this project in C++, but created a blueprint instance to have more control over the meshes and all and i discovered something weird: If my character spawns the C++ class projectile, it successfully changes color, but if i instead spawn the blueprint that inherits from that class, it won’t change color!
I don’t know why this happens so I’m reporting it as a bug…
This is the code on my projectile C++ class constructor:
static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere'"));
static ConstructorHelpers::FObjectFinder<UMaterialInterface> MaterialAsset(TEXT("Material'/Game/StarterContent/Materials/M_Basic_Wall.M_Basic_Wall'"));
if (MaterialAsset.Object && StaticMeshAsset.Object)
{
ProjectileMesh->SetStaticMesh(StaticMeshAsset.Object);
ProjectileMID = ProjectileMesh->CreateDynamicMaterialInstance(0, MaterialAsset.Object);
ProjectileMesh->SetMaterial(0, ProjectileMID);
}
NeutralColor = FColor::Yellow;
AllyColor_1 = FColor::Green;
AllyColor_2 = FColor::Blue;
FoeColor_1 = FColor::Red;
FoeColor_2 = FColor::Black;
ChangeMaterialColor(NeutralColor);
This is the code that i use to spawn the C++ version of the class (that successfully changes color):
FActorSpawnParameters SpawnParams;
SpawnParams.Instigator = Cast<APawn>(this);
ACodeBounceBallProjectile* Projectile = World->SpawnActor<ACodeBounceBallProjectile>(ACodeBounceBallProjectile::StaticClass(), SpawnLocation, SpawnRotation, SpawnParams);
This is the code i use to spawn the blueprint version of the class (which does not change color at all, i’m using the base material and its color remains white, screenshot in the next comment):
static ConstructorHelpers::FObjectFinder<UBlueprint> ProjectileBP(TEXT("Blueprint'/Game/FirstPersonBP/Blueprints/MyBounceBallProjectile.MyBounceBallProjectile'"));
if (ProjectileBP.Object) {
ProjectileClass = (UClass*)ProjectileBP.Object;
}
/////////////////////////////////////////
ACodeBounceBallProjectile* Projectile = World->SpawnActor<ACodeBounceBallProjectile>(ProjectileClass , SpawnLocation, SpawnRotation, SpawnParams);
Can someone explain to me what’s going on?