Blueprint References Help

Hi there,

I have setup blueprints for various systems within the game I am building - Inventory, Quest, Equipment, Abilities etc. They have to interact to a certain level and generally I setup the references to and from one another when those systems are spawned. They also reference the player, controller etc.

However there are instances where they need to retrieve other references. Rather than having lots of separate casts to, I was wondering if it were good code practice to store all the references in one game object, say Game Instance or Game Mode, and then cast to them and retrieve all references needed at the individual class level from there? I’ve looked at setting up blueprint interface or event dispatchers, but this feels the cleanest way I can think of unless I am missing something?

Thanks in advance!

Hey!

When each BP comes into being ( it’s own BeginPlay ), it needs references to other objects.

I think one of the most common ways is this:

Another way would be, as each BP starts, it saves a reference to itself in the game instance, and your other BPs get it from there. But that’s probably more hassle.

Event dispatchers and BP interfaces are defintely not what you need here.

BP Interface is for sending messages to another BP, so you already have the reference. I guess you could be sending a reference to yourself, but it’s a REALLY long way round…

Same for Event dispatchers, they are really more for sending a message to many BPs at once. Again you could be sending a ref to yourself, but it’s a lot of extra work. The piccy above is the most immediate way.

The only thing you have to watch out for is if the BP you’re looking for hasn’t been spawned yet. But ask if you wanna know about that…

Hey there,

Thanks so much for your reply!

I put the references inside the GameMode for now as GameInstance initiates before any of the references needed. Also as I understand it GameInstance initiates once when the game is first run and GameMode each time a level loads.

One issue I hit though is any actors in the level have their BeginPlay functions execute BEFORE the GameMode BeginPlay, which I think is contrary to Epic’s workflow documentation and doesn’t make any sense to me. That meant I had to use a blueprint interface to send out references from GameMode once they had been successfully setup. I’m sure there’s a better way of doing this!!