Character Blueprint not getting Referenced in Level

Hello I have a Character Blueprint. And I have saved some important variables in it which I will be using in every level of mine. For now I have 3 levels. In 1st and 2nd level, I’m able to get reference of character blueprint. In the third level. However the casting to Player Character Blueprint is getting failed.

Here are the ways I’ve tried:

  • Checked GameMode File of each level and added Player Character Blueprint in Default Pawn Class. This is same in each game mode file.
  • Checked if the Player Character blueprint is added into level.

In one scenario I’m getting casting success and in other scenario its getting failed. The settings of Character Blueprint is same.

Don’t know what is wrong. Please help me out.

Can you post a screenshot of how you are casting and calling for the variables? Since you want to use the variables in all levels you could move them to the player controller and have the level or game instance get the variable values and they could carry over to each level as well.

If you’re using your character in a level blueprint, there may be cases where the character hasn’t been initialized yet. So for instance if you’re using it as the first thing from the OnBeginPlay event, you would sometimes get a fail because sometimes the character isn’t initialized by the time the event runs. If you put up a delay node for a couple of seconds you should be able to get a consistent result.

Okay, so its not a bug. I was getting very irritated by this fact. Also consider this situation, if I haven’t included character blueprint in the level, but I’ve mentioned the character reference in the level game mode file. This way of adding character blueprint is also workable ?

Technically it is, but your Game Mode blueprint has access to different values than your level blueprint. You need to figure out if you are OK with only using your character reference only in a Game Mode context or whether you need it in a level context. Remember that Game Modes are level indepedent - you have one instance of a Game Mode for the entire game session you are running.

If this answered your question, please feel free to mark it as such. Thanks! =)

Hello Sentura,
Your argument is correct. However after lot of trail and error with my character blueprint referencing, I found that in only one level out of 7 levels, its not getting referenced correctly. (As the level loads up, objects which are taking information from character blueprint are unable to access it.) Can you deduce any solutions ?

Depends. Which level is it? What kind of logic do you have in that level? You have to give me the complete picture if you want help.

I’m working on a adventure game. Its a 2d. Player is first person. I wanted a class where I can save player related functions. Like inventory information. And then different objects and npc will interact in there own way after receiving that item value from my player class. Also some basic GUI functions which take player input, I mention them as well. For this structure I choose Character blueprint. Is this information sufficient ? Please let me know

You really need to use the GameMode blueprint for those kinds of options, not individual level blueprints. The GameMode blueprint will stay persistent during each game session; level blueprints will not. So at any given time, if you want to save stuff and make sure it’s consistent, you need to use the GameMode blueprint.

Hello Sentura,
I’m stuck very badly. I have only one game mode c++ file from which I made a game mode blueprint file. “Default Pawn Class” has Player Character blueprint. This blueprint holds all the information about player, like which quest he is in, what inventory it has. Everytime a level loads up, this player character class populates the data from SaveGame Blueprint. Since this functionality is working perfectly file, I didn’t felt to use Game Mode blueprint to save player related information.
Here is my scenario of structure, Please feel free to ask anything you didn’t get.

  • My inventory system is integrated with Player Character Class. This inventory system gets lot of data when player roams in the level.
  • I have 6 levels. With same game mode. In game mode, I’ve already mentioned my character references in “Default Pawn Class”. My character blueprint is running in all levels. Though please keep in mind all of my levels does not have much art in them, still core mechanics are functional.
  • One of the level has lot of art assets in it. I’ve taken reference of game mode blueprint,character blueprint and controller blueprint in its level blueprint.

                      Now problem comes here: 

My character blueprint is not getting initialized in the above level I mentioned. I get null reference from game mode, controller and character blueprint. And hence whole of my game code crashes.
Surprisingly, my other levels are working fine, they too have referencing of game mode, character blueprint. But their, there is no referencing issue error.
Only in this level, I’m not able to access those singleton classes which I’ve mentioned in GameMode blueprint.

Please any enlightenment on this issue would be grateful.

Fieol

Here is the Scenario Explained with Screenshots:

My level Blueprint where I’m accessing these classes (game mode, character , controller )

When I start the level from editor. There is no referencing issue. All of the class casting is successful. Here is the screenshot. See Top Left Debug Logs.
**Conclusion is : if I play the level by opening it explicitly in Unreal Engine. It works perfectly fine ! **

Here is the screenshot of world settings of that levelblueprint.

BUT…
If I open up this level from another level, this level is not taking these references of (controller,game mode, character BP) . My question is:

  1. Same game mode is running in every level, why this level only getting reference issue.
  2. I’ve set the correct options in "Default Pawn Class’ and “Controller Class”, in the game mode. Still its not making these blueprints available to level. Why so ?

Note:

Character Blueprint , Controller Blueprint, Game Mode Blueprints are derived from a C++ class of respective types. (Such as: Character Blueprint derived from ACharacter Class, Game Mode derived from AGameMode Class)

I’m very much troubled by this bug. Don’t know how to fix it, please help.

I’ve shifted my base gameplay code to GameMode Class. And I can access it in any level. This solves the problem temporarily.