I’m trying to figure out how to get a really simple effect with PCG. You can see it here in the Runtime Generation mode documentation: Using Runtime Generation
I want my PCG graph to be running and updating in real-time around the player, spawning foliage instances on top of meshes that are being spawned by another system - with the player being able to in principle keep traversing the world endlessly, with the PCG always populating some foliage instances around their position.
My issue is that I cannot figure out how to get this to work within an unbounded volume. I’m able to replicate the results in the docs by having a PCG volume that’s set to generate at runtime, and if I’m using hierarchical generation, then when I enter that volume, then I will only see foliage spawned around me.
However, if I set my Surface Sampler in this case to be unbounded, then everything fills up with instances, all of the time. I’ve tried creating a bounding shape off the player pawn, or moving the volume brush with a blueprint, but none of this dynamically updates the PCG generation, if it has a volume, it seems to remain static at runtime.
What I’d like is to be able to spawn meshes into the world at runtime, and have PCG dynamically generate foliage around the player, when the player walks on them. This seems like it should be possible?
I’ve managed to fumble my way into some progress on this I guess. This post was helpful in figuring out how to sample static meshes from arbitrary actors in the scene.
It feels a bit awkward that I can’t, say, get an array of actors and then iterate on that array to get multiple actor properties from each actor as far as I can tell - both ‘Get Actor Property’ and ‘Get Actor Data’ don’t seem to allow you to pass anything into them, so they’re forced to fetch their actor independently(?).
But, the loop subgraph does allow me to iterate over those two arrays simultaneously:
It feels awkward, but it works - I’m successfully able to grab a static mesh from each of my spawned actors, scatter positions on it, and then transform those positions to where the mesh is. That enables this kind of labyrinth being spawned under your feet to work:
The road is being generated out of tiles around the player as they move about, whereas PCG successfully grabs those tiles and spawns some placeholder bushes across the surface.
My remaining puzzlement though is that I’ve gotten this to work while largely having to ignore the hierarchical generation side of things. Bushes generate immediately, on all tiles that exist, and I’m still not sure how to constrain this generation to just be in the vicinity of the player. Additionally, when the network refreshes, it seems like all of the vegetation sometimes pops in and out of existence, which suggests that it’s not managing to do any caching and just regenerates all instances when it updates (maybe when a tile is added or removed?).
I’d love to figure out a way to make this more stable and constrain the generation to be just around the player, to keep it performant - e.g. having 1km x 1km meadow tiles being spawned at runtime by a blueprint, but only scattering in a 100m circle around the player, as you move around from tile to tile.