Strange problem with player start orientation on procedural level

Greetings,

I’ve got a very strange problem. I have a labyrinth generator that I’ve been creating. All the labyrinth logic is created in a C++ class, and the geometry is all added to the world through blueprints. I prefer to have the generation code in the Construction Script so I have visual feedback in the editor. This is not a problem.

My “Build Labyrinth” BP function calls my FCreateLabyrinth function from the C++ code which creates the data needed for the labyrinth build (all the individual tile data, picking the starting spot, picking the ending tile, and also generating the solution to the maze in an array from start to finish). This works great. I also have BP functions for placing the physical starting and ending portal meshes and particle systems. And, finally, I have a BP function that places the player at the starting point.

When I run all this from the OnBeginPlay in the Event Graph everything works fine and my player starts out on the starting tile with the correct rotation and positioning.

HOWEVER: if I move just my “Build Labyrinth” function to the Construction Script, my player spawns in at whatever direction he happened to be looking in the editor. (Even though my “Place Player at Start” function is still in the Event Graph in the OnBeginPlay event. There is nothing in my “Build Labyrinth” function that has anything to do with the player, aside from simply picking the Tile Index where the player start should eventually be. (But not actually PLACING any sort of player start there. Simply choosing the index number of the tile where the player should eventually start.) Build Labyrinth simply places the physical geometry like the floors, walls, lights, pillars and, optionally, ceilings). There is literally NO reason why the location of this function should have any bearing on the rotation of the player at the start of the maze.

So to recap:
With Build Labyrinth in the Construction Script, my player doesn’t rotate correctly, but is placed correctly from the OnBeginPlay.
With Build Labyrinth in the Event Graph, my player rotates and places correctly from the OnBeginPlay.

I’m at a loss.

This is the rotational code that I’m using:


(But without the “Teleport” bit set. That was just for testing purposes–has no effect on this.)

Okay… Took a shower this morning and was thinking about this. Came to my development station to test a theory I had while I was in there and turns out that when I’m building the level in the Construction script, all my array data that I’m creating gets lost when I hit the “play” button. (Tested this by moving my set of invalid switches onto the “south” pin of the rotator for testing, and kept the blueprint up.) When I hit ‘play’ the ‘0’ pin fires from the switch and therefore bypassed the four directional rotators.

Glad I solved that problem. (I guess I need to shower more.)

So now I’ve got another one: How can I spawn a PlayerStart in Blueprints? I’ve been trying to do that (and searching for an answer to it, also) but to no avail. Or should I be spawning something else? If I can spawn the PlayerStart directly, then I can just move the location of this blueprint function to be processed with the rest of the level generation (altered to work with setting the position and rotation of the PlayerStart, of course), and I’ll be done.

I like how the generator is turning out. It’s got some nice features to it, with more to come, and when I have it perfected I will probably make it available to the public, but for now, this is a fun project for getting back into game programming. (It’s been QUITE a while, and things have changed so much since Doom, Doom II, Hexen, Heretic, the original Unreal Tournament! lol)

Anyway, I’m going to keep trying to discover a way to spawn the PlayerStart pawn from blueprints, but if anyone has a blueprint image of theirs that I could see, I’d appreciate it! Thanks!

  • “the showered one” Bublitz

BTW: Just in case you’re interested, a couple of the features of the maze generator I have right now is you can either specify a size, or have the generator pick a random size for you. Independent X and Y number of tiles for non-square mazes. You can leave it totally random, or use a seed for a reproducible maze. Set the tile sizes based off of the static mesh sizes (rectangular meshes and mazes are completely acceptable) And at the moment I have an option to give the maze a ceiling, or leave it open to the outside. Here’s an example of a generated maze. (The brown tiles are the solution, the bluish portal is the start, the red particle system is the end. The generator places the beginning always in a “one way out” square (dead end) and then traverses the maze to find the farthest traversable point from the start to place the end point. The two could literally be on the other side from the wall from each other, but still be the farthest apart as far as walking distance.

So I’m making a game that requires this kind of functionality. the spawning a player on a procedural level. As far as i know you cannot use a blueprint to spawn a playerstart.

Though what I do is create a special blueprint that spawns your character at this blueprints world location and has the playercontroller posses that spawned character. you just spawn this blueprint where you’d like the player to show up Bam. or (place it into the world if your level will always end up at the same place. this is redundant though)

Thought about that, spawning a dummy object of sorts, then possessing it at startup. But was really hoping to simply have the Blueprint place a real PlayerStart for me. But, like you say, I’m finding that it doesn’t seem possible to simply spawn a PlayerStart. That’s a shame. Would make many things very easy. One simple BP function could prevent a lot of extra work for us. Oh well, I’ll test this and create something when I come back home a little bit later and post my results and show my work. :slight_smile:

Actually, thinking about this earlier, I think the REAL problem I have to get down to is why is my data invalidated and returning ‘0’ for the directions available from the starting location when I play the level. Apparently my array data is gone after I start the level. But this doesn’t really make much sense since my other functions that rely upon it the seem to work just fine.

Anyway, unless someone has had a similar problem and knows what’s going on, I guess it’s just back to trying to debug again tonight. At least I know why the problem was happening in the first place now.

Thanks, SaxonRah, for the suggestion above, though. :slight_smile: Really appreciate it!

I’m seeing what’s going on here. My “GetDirectionsAvailable” is implemented in C++ code, and for some reason when I try to access my array from the code when I’m in the game, I’m not able to gain access to it. But if I access it through blueprints, I’m able to access it. The C++ function works and evaluates just fine if I run a compile from within the editor.

From the editor:

From the game:

And my C++ code:

(I’m seeing that this is more of a C++ related problem now, so if this needs to be moved, please do so.)
Is there something I need to do with my code for it to return the correct value? Why does it make a difference if I’m accessing the array through the BP or the code? I guess I’m not really understanding how this is working. My base class is my C++ Labyrinth class, and my Blueprints LabyrinthGenerator class is a child class from it.

FIXED IT!

Scrapped using my C++ function in the blueprint, and just added the UPROPERTY tag to the element in my FSLabyrinthTile structure. Good to know for future reference.

struct definition.png

Still don’t know why this doesn’t work, but I’ll leave that for the C++ forum and not here. Just thought I’d post my solution for posterity.

One last thing: It turns out that after adding the UPROPERTY and BlueprintType, the C++ function started working. So I guess if you’re going to have your Blueprint access an array element even from a C++ function, it doesn’t matter that the function itself is BlueprintCallable, but the structure you’re trying to read from the array has to be a BlueprintType, and the individual structure property you want to return the value of has to also be BlueprintReadOnly (or, BlueprintReadWrite). I never realized that before. I certainly didn’t read that in any of the docs.

I just assumed that as long as my access function was callable from Blueprints, it wouldn’t matter that the structure properties weren’t available to Blueprints since it was the C++ code that was calling it and returning the value to Blueprints.

I’m back to my original function since it’s quicker and easier to me than creating the linkage in BP.