Struggling here to what seems like a simple problem. I’ve set up a function to collect the required variables to generate terrain mesh. But when i press play on the editor it always crashes on the CreateMeshSection() method from the procedural mesh component:
The error message highlights the line where the create method is called. As the error is an exception_access_violation, i thought to check whether the component the method is called on is set.
I’ve tried marking the variable as EditAnywhere in the Uproperty Section. I’ve also tried deleting and regenerating my project files.
Why is does this procedural mesh component variable have a value of nullptr when I’ve set the value of it above in the constructor? Is there something I’ve missed? The generate function this is contained in is called in blueprint, but all of the logic is done in C++.
In your create mesh section you have the wrong if declaration.
You can’t be testing if equal to nullptr and then calling create mesh section. You need to test if it’s NOT nullptr, which means that it’s actually initialized and of type UProceduralMeshComponent.
So it’s just a typo on your end.
Try
if(_ProcTerrain != nullptr){
_ProcTerrain->CreateMeshSections( rest of parameters here )
}
That way the create mesh section will be called if the initialization in the cdo is correct
I’m not sure if i’ve misunderstood but the reason i tested to see if component was equal to nullptr was simply to check if it’s value had been assigned in the constructor. The main issue that I’m having is that the variable is not initialized when I think it should be.
I’ve also got no errors building from my IDE so it looks to be included correctly. I’ve the ProceduralMeshComponent.h at the top of the cpp and the class declared in the header.
The function is called in blueprint on begin play. It’s called within a nested for loop since i’m generating multiple sections of terrain.
I’m still not used to TObject pointers since the older versions were more straightforward. I sometimes forget that you need to call get to actually init them.
If the _ProcTerrain remains empty then try creating it with a NewObject command.