I was following this tutorial on eu4 : https://www.youtube.com/channel/UCnO…O1WwKFq-5Pvj0Q
At 13.00m he create a UMaterialInstanceDynamic and he does the SetVectorParametersValue on his material. I’ve try to do it in the basicProjectile.cpp file (OnHit function).
But visual studio tells me I can’t do that. Also, Visual studio auto completion didnt work on MatInst.
void AMaze_V_1_0_0Projectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
// Only add impulse and destroy projectile if we hit a physics
if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL) && OtherComp->IsSimulatingPhysics()) {
OtherComp->AddImpulseAtLocation(GetVelocity() * 100.0f, GetActorLocation());
UMaterialInstanceDynamic *MatInst = OtherComp->CreateAndSetMaterialInstanceDynamic(0);
if (MatInst) {
// Error Here on MatInst ... Dont know why
MatInst->SetVectorParametersValue("Color", FLinearColor::MakeRandomColor);
}
Destroy();
}
}
Then, the reason why visual studio is complaining is the GENERATED_UCLASS_BODY() macro inside MaterialInstanceDynamic.h
To keep it simple, at the end of the macro, there is a “public:”, but visual studio doesn’t know it.
The result: it thinks that the function is private and this is why it doesn’t autocomplete you.
But it should compile no problem.
Cheap fix if you have the engine source and you want to have the autocomplete:
Search for “GENERATED_UCLASS_BODY()” in the entire solution and replace it with “GENERATED_UCLASS_BODY() public:”
Note:
I do this everytime I get a new engine source code and everything works fine, but make sure that it does not break anything for you before doing it.
Projectile.cpp (54): Note: You must not use the source type or the manufacturer’s overload solution? was ambiguous?
Projectile.cpp (54): error C2664: ‘void UMaterialInstanceDynamic :: SetVectorParameterValue (FName, FLinearColor)’ ?: Unable to convert argument 2 of ‘FLinearColor (__cdecl *) (void)’ in ‘FLinearColor’
Oh wow, I didn’t see the missing () either, sorry.
And for the include, it is better to keep it.
Most of the classes are not included by default.
If you don’t know where to find it:
Go into the API and search for it.
Go at the bottom and you will find the include file.
While being there, you can also take a look at the dependency module, if you’re not adding it into your build.cs file, you will probably get a link error during compile.