How to dynamically reference not-in-scene blueprints?

This referencing thing in Unreal has proven to be the most challenging thing to understand.

I have here a Game Mode blueprint I’ve name Game Manager which contains a list of different components that contain data to be processed. The Game Manager itself contains variables and its components need to use that data in method calls. What I can’t figure out how to do if build a link to the Game Manager inside its components that need to return variables from it.

100281-untitled.png

This here is the component list in Game Manager. Puzzle A and Puzzle B are variables that serve as hotswap sockets for the other puzzles in the list. Each Puzzle object has a text variable called ID that I need to reference.

This here is a method inside the Instruments component in Game Manager that sets a combined ID based on the ID from Puzzle A and Puzzle B. So far I’m just trying to get the variable. This is where its going wrong saying that it doesn’t access anything.

I can’t figure out how to set a reference my Game Manage in that method.

I tried doing this in the base event graph in Instruments, but it didn’t seem to work.

100284-4untitled.png

And I have no clue how to reference it here if its not on the list.

Hi there, is there any reason why you need Components for your solution? Do you have multiple levels and depending on which level the player is, you will select the appropriate component and its data?

I was just wondering, because there is probably a much easier solution that makes your life easier, if i would know what you mean with hot-swap :slight_smile:

But anyway: Well in your screenshot, this IS how you set a reference to your GameMode (as you called it GameManager), so you are doing good. Just make sure that you have set the GameMode in the ProjectSettings or within the WorldSettings.

Because I want these objects to be instantiated on the Game Manager object and not as separate entities. I thought getting Game Manager members from inside these components would be easier and require less linking.

I have a working version solely in C++, but that has turned into a huge mess trying to integrate UI management.

I guess I could try passing in the puzzle objects to the method as parameters since trying to do a get isn’t working.

The system is randomly selected puzzles. There are 8 different puzzles that are randomly paired together for a total of 16 combinations. Each has a method called IsSolutionCorrect which compares the user’s input with what the correct sequence is. Each puzzle is based off the same base class which is what my PuzzleA and PuzzleB variables are. The method gets called from those variables when the game goes to check the solution. If correct, the game then resets those variables with another pair of randomly selected puzzles.

Well so let’s fix things:

If your GameMode cast fails, then you have an issue with your GameMode setup anyway, no matter how you want to pass it to your Components.

I guess your EventBeginPlay is within the Puzzle Component?
What does this print out if you put this into your LevelBlueprint?

100381-checkgamemode.jpg

Happy to help :slight_smile: Marooney

It says GameManager24 then keeps incrementing that number on each run. I didn’t know a level blueprint was a thing. I’ve been trying to log everything in the game mode which does not seem to be running because its not getting the orange execution bars while running from begin play.

These are the errors I’ve been getting

LogGameMode: Warning - PATHS NOT DEFINED or NO PLAYERSTART with positive rating
LogScript:Warning: Attempted to get an item from array PuzzleListA out of bounds [0/0]!
LogScript:Warning: Attempted to get an item from array PuzzleListB out of bounds [0/0]!
PIE:Error: Error Blueprint Runtime Error: Accessed None trying to read property Puzzle A from function: 'SetWorldName' from node: Print String in graph: SetWorldName in object: Instruments
PIE:Error: Error Blueprint Runtime Error: Accessed None trying to read property Puzzle B from function: 'SetWorldName' from node: Print String in graph: SetWorldName in object: Instruments

Oh, thats weird. I was expecting that your GameMode will not be executed at all, but because an issue with the setup and not an incrementing counter in the name.

Well ok I could not figure out how to reproduce his counting number. How do you Launch your application? Not as Win-Application?

Anyway, what i would do: Set the GameMode back to the default GameMode in your ProjectSettings and in the Level. Save, then Play. and then just to be sure restart the editor. And then you set your GameManager in the Project Settings.

Perhaps that changes some weird issues with the editor.

Okay I that so now nothing in my custom game mode is being executed. No errors being generated.
I’ve been just playing it in the editor, so it is a windows application(?)

Since my mode mode seem to be executing, my issue seems to start here:

 LogScript:Warning: Attempted to get an item from array PuzzleListA out of bounds [0/0]!
 LogScript:Warning: Attempted to get an item from array PuzzleListB out of bounds [0/0]!

I don’t know where thats being generated.

The issue seem to start here in this method. This method in Game Manager is called from begin play in Game Manager’s event graph. I’m not quite sure what it means by out of bounds [0/0]. I know what out of bounds means, I just don’t know why. When I iterate through the lists with get display name, I get the correct puzzle names.

I found it. I was trying to execute other things before initializing my lists.

But I still cannot get my print function for the ID’s to print anything.

Here’s 3 print blocks. The first one should have printed “2B4A” before the display names, but it didn’t. That’s strange because I have the ID variable set tot he proper default value in those blueprints.

Wait…

I found it.

Apparently there’s a difference between this variable in Game Manager.

And this one in the blueprint itself.

100386-9untitled.png

Ok, just wanted to be sure.

Well, you can configure your values in the component and override them in the Actor/GameMode/… when using them. Therefore you need tho set the Variable to Editable to avoid issues. If you see the yellow reset arrow then you have overriden the original value. In your case with an empty id.
So you need to configure the IDs of each PuzzleComponent in your GameManager.

And you need to know. As soon as you set the components default value to the same value as an Actor that uses it, you cancel the override status in the Actor. If you then set the value to something different within your component, you will change it for the Actor too, without even knowing. Not sure if this still can happen, but happened to me sometimes.