I recently got normal static mesh actors spawning at runtime via c++ but now I want to be able to do the same using destructible meshes. I’ve created a destructible mesh from a cube, made sure it works how I want it, but when I try to spawn it in code unreal/visual studio doesn’t recognise UDestructibleMesh even though I have the necessary header file included. Has anyone done this before and can show me the way to go about this?
UWorld* const w = GetWorld();
ADestructibleActor* d = w->SpawnActor<ADestructibleActor>(destructible, spawnPosition, FRotator::ZeroRotator);
destructible is declared in header of the class so i can set it in the editor:
// Destructible actor used to control the asteroid flight
UPROPERTY(Category = "Asteroid Spawner", EditInstanceOnly)
TSubclassOf<class ADestructibleActor> destructible;
Thanks for the reply and for showing me your method. Question though, what if you’re just using a mesh you created and didn’t assign to anything like you seem to have done with the Asteroid Spawner? I just want to generate my created destructible mesh because it’s not in any sort of category if you understand what I mean.
Sorry…not understanding how what you’re trying to do is different from what I’ve done. I created a destructible mesh in the editor from an existing static mesh. Then, I place my asteroid spawner volume in the level and set the “destructible” to be that destructible version of the asteroid and spawn it with the code above.
Ah ok, sorry I didn’t know you placed your mesh in the level first then spawn from that.So your asteroid spawner volume is the original destructible mesh, you create 1 instance of it in your level then spawn more using it’s name Asteroid Spawner in code as its category? Is that right?
No, mesh isn’t placed in the level. A volume that defines the space for the asteroids is placed in the level. then, it has a reference to the destructible mesh actor listed in the content browser.