I have the following scenario in UE5.3:
At runtime, multiple static mesh actors with static mesh components are spawned to the scene after an API call that returns locations where those actors should be in the scene
This is the method for spawning:
AStaticMeshActor* ALocationActors::SpawnStaticMeshActor(const FVector &InLocation, UStaticMesh* meshToUse)
{
AStaticMeshActor* MyNewActor = GetWorld()->SpawnActor<AStaticMeshActor>(AStaticMeshActor::StaticClass());
MyNewActor->SetMobility(EComponentMobility::Movable);
MyNewActor->SetActorLocation(InLocation);
UStaticMeshComponent* MeshComponent = MyNewActor->GetStaticMeshComponent();
if (MeshComponent)
{
MeshComponent->SetStaticMesh(meshToUse);
}
return MyNewActor;
}
At runtime, if I Eject (F8) Iâm able to see a property on both actor and static mesh that I need to be able to change, and the property name in editor is called âFar Shadowâ under Lighting â Advanced â Far Shadow:
I can change that property in the editor when ejected, and it does what I want it to do, however, how can I change that property in the C++ code?
Iâve tried a couple of things and searched for ages but failed to find a proper solution for it because of my lack of experience with UE and C++ (even though I have 15+ years of experience in other languages and frameworks).
Here is one simple try that failed with compilation error "Cannot resolve symbol âSetPropertyValue_InContainerâ ":
AStaticMeshActor* actor = SpawnStaticMeshActor(unrealPosition, mesh);
UProperty* Property = NewObject<UProperty>(actor, "Far Shadow");
Property->SetPropertyValue_InContainer(actor, true);
This really looks like a simple problem with simple solution, set something in the code that is already in the editor?
Where do UE devs find examples of the working code?
Iâve tried google, bard, chatgpt, github copilot⌠all of them seem to lead in the wrong direction, and none of them seem to be helpfull in this scenario and a lot more other simple scenarios like this.
UE documentation such as this one:
does not seem very helpful either, just showing the function name and class owner of the method, no examples, no explanation, no nothingâŚ