How to Affect the PCG in Runtime with Blueprint

Hi,

I am experimental the new PCG plugin in UE5.2 from the source build. I try to generate trees from the PCG graph and then create a door that will change the value of the blueprint variable which will be used in the PCG graph. I thought this will change the PCG value during the game. Although this is not working. Does anyone know where could be wrong? Here is the video of my code.

In this video, I create a PCG graph called “PCG_Grass” and I use the “Get actor property” node to get the actor from the world by tag. Although I tried to get it from the parent, it gives a warning that cannot find the variable with the name. After I get the value, I try to toggle the value in the editor, you can see that the content is changing but when I start the game and try to change it when overlap with the door, the value changes but the content is not.

Thanks for your help.

6 Likes

Hi @patrickzw

If i remember right from the recent GDC videos that it was mentioned that currentyl PCG editor only right now, this may change on release of full 5.2 or even 5.x.

I wouldbt be using it for anything substantial right now IN GAME anyway as they have said numerous times it could change, just like the new Strata/Substrate materials. They are still work in progress so beware.

BUT i might be wrong if anyone else can clarify?

2 Likes

Hi, @High500

Thanks for your reply, I double-checked Arran Langmead’s PCG presentation in GDC. At the end of the video, he said the stuff he showed is editor only, and they do have game involvement which can ship the empty level and completely generate it when the player loads the game.

While writing this, I checked again the " New Tools for Building Photoreal Worlds in Unreal Engine 5.2 | GDC 2023" video from Unreal about the large world prototype around 12:40. He said, “The hierarchical generation concept is to be implemented natively in the framework in the very near future.”

So yeah, I think you are correct.

LOL, I looked too closely at the demo to ignore the sentence. I also won’t use it in any game right now, just experimenting, thanks for the advice.

2 Likes

hey that doesnt mean dont play with it and conceptualise it, just lay off anything heavy for now. You never know when it would be available at runtime!

1 Like

Your debug log on the top left corner seems to indicate that the value is put to 1 and immediately put back to 0. Might be the issue? Your setup seems fine otherwise.

Thanks for your reply.

That is because I set the value to 1 on the beginning overlap when entering the box collision of the door and then set it back to 0 on the ending overlap of the box collision.

The problem here is, the value changed in the blueprint correctly, but it will not pass to the PCG graph while it changed in the blueprint. I cannot find a way or node that let me update the “Get Actor Property” in the PCG graph when the value changed in my blueprint.

The logic was when I overlap with the door, the value changed to 1, the “Get Actor Property” get updated, and then the PCG graph will spawn the second static mesh. Then when I end overlap with the door, the value is back to 0, and the “Get Actor Property” updates, and then the PCG graph will spawn back to the first static mesh.

This logic is working within the Editor when I change the value in the door actor’s detail, but not in runtime.

I just found a workaround.

I created two PCG graphs with the same node, but the static mesh is different in the spawn static mesh node.

I named the two PCG graphs “PCG_Sphere” and “PCG_Cube” with these nodes.

Then I create an Actor containing a door static mesh and box collision and the code will be this:

So when I collide with the door, it will change the graph of the PCG volume in the level and then set it back when I end up overlapping with the door.

Here is the result:

3 Likes

after applying your workaround I can’t seem to get the pre-existing graph static meshes that are spawned in to go away when the second graph static meshes appear any help would be greatly appreciated :slight_smile:

The two static meshes spawned at the same time? Maybe try to use the “clean up” node before the generated node.

1 Like

ah it seems I forgot to change the PCG component for the graphs to generate on demand instead of on load. currently working on a PCG building with varying room detail based on when a player enters a room. Out of curiosity have you figured out any way to change the seed of the graph being generated once the collision is activated?

any possible insight on how to change the seed of the PCG_Graph every time its generated when passing through the door? :smiley:

1 Like

Currently the increment will print similar to the original issue. Also the seed will change if I manually change the integer value in the editor or in the blueprints event graph.

my static mesh spawner is currently using the ToParamData to change the seed.

image

Any input is greatly appreciated. Still learning the ins and outs of UE5! :grin:

Hi,

I finally find a way that to change the PCG content in the game. You do not need to use the set graph node to change between two graphs, right now, you can switch the static mesh in one PCG graph.

Here is the door blueprint I have.

In this image, you can see that I set up the “switch” variable, and this value will decide which static mesh it spawns in the PCG graph.

Here is the PCG graph node. I use the “switch” property here to produce a new column to determine which static mesh to spawn

With this logic, I can now play the game and when I go into the door, it will change the static mesh and then when I leave the door, it will change back.

For your changing seed. You can use the same way, here is the logic in the door.

You can see, I set up the “seed” to constant. You can use “random float in range from stream” to set the “seed” to random.

I changed the seed for the surface sampler so that the box it spawns will be random. When you play in-game with the “seed” in constant, it will change all the points’ locations and then when you leave the door, it will change it back. Since the same seed will always spawn in the same way.

Here is a short video for the final result.

2 Likes

Awesome thanks for the insight working very well after implementing the above mentioned logic. here is the final result!

https://youtu.be/dE5cU8XFYH4

Hello,
The PCG in UE 5.2 is awesome, I couldn’t wait for it to be available for packaged game.
The PCG nodes (Set Graph, Cleanup, Generate… ) works well in editor, but not in packaged game. The game freezes, when any of the PCG nodes are executed at runtime in level blueprint.

So, I did the workaround as mentioned below, hope it may help someone desperately wanted to use in game executable right now!

  1. Add multiple PCG volume(s) for each PCG graph that you wanted
  2. Set PCG volume as Movable instead of Static
  3. Set all the PCG volume location as required in final game executable, so that the PCG by editor performs as intended for final game.
  4. In level blueprint (or could be any blueprint), based on conditions, Move the PCG volume(s) location ‘z’ axis value for up / down to visible / hide under the ground level.

Note: I use Set World Location node on PCG volume → Brush component to move up / down.

Thanks,
Rush At Games.
#Roxroria

2 Likes

ah cool! Thanks