Hi. I’m having an issue with implementing an architecture I want in regards to UStaticMeshes. My use case is to have arrays of data for voxels and have an array of UStaticMeshComponent pointers so I don’t have to have voxels spawned in at all times. As such, I can’t use constructor methods. When using NewObject() however I am experiencing a crash, and suspect it is due to memory allocation.
For efficient voxel references, I am using an array of pointers to UStaticMeshComponents as follows:
UStaticMeshComponent** visibleMeshes[WORLDWIDTH][WORLDDEPTH][WORLDHEIGHT];
When trying to instantiate the objects themselves I am using:
(*voxelData.visibleMeshes[x][y][z]) = NewObject<UStaticMeshComponent>(this, UStaticMeshComponent::StaticClass(),TEXT("Voxel"));
I’ve tried multiple variations of this line but experience a crash every time. Would use the new keyword, but I don’t believe that’s how NewObject instantiation works. Obviously however there is no actual memory location to assign to in this case. It is floating so to speak other than for the pointer reference. Is there a solution as close to this as possible? My use case really favours this kind of approach, but can’t nail this one line.