Event dispatcher called from the game instance not working

I’m using a custom game instance to pull in data from a data table and store it in an array. When it has the data I call an event dispatcher.

I have binded my level blueprint to this dispatcher but it isn’t firing.

I have selected the correct game instance class in project settings.

Could you guys take a look please? :slight_smile:

Game instance:

Level blueprint:

1 Like

The Init event in the game instance is called waaaay before BeginPlay in the level. Your game instance needs to trigger the event a bit later.

2 Likes

Adding a delay worked but this doesn’t feel very safe. I don’t understand why it would matter how early the game instance calls the dispatcher?

Is there an event generated when the game instance has been initialised?

It’s your “Bind Event to Team Data Loaded” node. This is executed WAY after the game instance is initialized. So all that stuff in your game instance event is executed well before any binding happens and that’s why GetTeamData event isn’t called. Said differently, when “Call Team Data Loaded” is executed, nothing has been bound to that delegate yet because your BeginPlay event will execute WAY later as @ClockworkOcean mentioned.

A better way might be to have a flag in your game instance that is set to true once the team data is loaded (and still call the delegate). But in your begin play, you would check the variable and if it’s set, call GetTeamData directly instead of binding. If the variable is not set, then bind.

BTW, don’t give me any credit for answers. I’m not answer sniping. Give it to CO if you get it working.

2 Likes

Ah ok I understand now.
Is there a more “standard” way to retrieve data from a data table and have it available for all levels to use? Should each level just have it’s own data table access logic? Ideally I just want to retrieve it and sort it once. Also; having it already in an array I thought would be more efficient?

1 Like

You can do it once in the GI, but just don’t use a dispatcher.

Implement your own dispatcher in the GI. If things aren’t ready, the GI notifies them when it is. If things are ready, it just notifies them immediately.

So this wouldn’t use an ‘actual’ event dispatcher, it would be your own code.

1 Like

Thanks, I will give it a try! :slight_smile:

1 Like

Hint: you can make a great event handler with a map string:’array of actor reference’ :wink:

1 Like