Hi beeceedee, I’m not really sure you understand the issue right here.
I will try to give you more details and code. The code comes basically from the lesson “Dynamically Constructing UObjects” inside the Udemy VR course that I am following currently.
First things first the Udemy VR course from Sam Pattuzzi (GameDev.tv) have very good quality and we need more VR open XR C++ Unreal skills instead of blueprint solutions on the market. I’ve integrated the code example from lesson 22 in my UE5 solution and the editor crashes with the issue that I sent before.
I’ve changed the code inside the for loop example now with the CPP file code below and duplicated this for the other controller as well (I want to use that for the second controller as well).
With this change inside the code, the editor doesn’t crash now but I can’t spawn a spherical element at the path points, anyway I can’t see them.
Course Example;
void AVRCharacter::DrawTeleportPath(const TArray<FVector> &Path)
{
UpdateSpline(Path);
for (int32 i = 0; i < Path.Num(); ++i)
{
if (TeleportPathMeshPool.Num() <= i)
{
UStaticMeshComponent* DynamicMesh = NewObject<UStaticMeshComponent>(this);
DynamicMesh->AttachToComponent(VRRoot, FAttachmentTransformRules::KeepRelativeTransform);
DynamicMesh->SetStaticMesh(TeleportArchMesh);
DynamicMesh->SetMaterial(0, TeleportArchMaterial);
DynamicMesh->RegisterComponent();
TeleportPathMeshPool.Add(DynamicMesh);
}
UStaticMeshComponent* DynamicMesh = TeleportPathMeshPool[i];
DynamicMesh->SetWorldLocation(Path[i]);
}
}
my functional code:
void AMy_VR_Character::DrawTeleportPath_R(const TArray<FVector>& Path)
{
UpdateSpline_R(Path);
for (int32 i = 0; i < Path.Num(); ++i)
{
if (TeleportPathMeshPool.Num() <= i)
{
DynamicMesh_R = NewObject<UStaticMeshComponent>(this,
UStaticMeshComponent::StaticClass(), TEXT("DynamicMesh_R"));
DynamicMesh_R->RegisterComponent();
DynamicMesh_R->AttachToComponent(VRRoot, FAttachmentTransformRules::KeepRelativeTransform);
DynamicMesh_R->SetStaticMesh(TeleportArchMesh_R);
DynamicMesh_R->SetMaterial(0, TeleportArchMaterial);
TeleportPathMeshPool.Add(DynamicMesh_R);
}
DynamicMesh_R = TeleportPathMeshPool[i];
DynamicMesh_R->SetWorldLocation(Path[i]);
}
}
my Header file;
public:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "VRCharacter|TeleportPathMeshPool")
UStaticMeshComponent* DynamicMesh_R;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "VRCharacter|TeleportPathMeshPool")
UStaticMeshComponent* DynamicMesh_L;