Blueprint/Actor send value to LevelBP

I have an BP Actor that has a room with a collision box, when the player enters I want it to increase score in regular level BP so I can use this value for calculating room gen.

This code does return the string successfully but Idk how to have it add a value to a variable in LevelBP

I’m pretty sure you can talk to the level BP using an interface :slight_smile :slight_smile:

I’m not aware of any way to get access to the level BP. Even with interfaces, it would have to be the Level BP that sets it up and calls the interface.

If this is single player, I’d just put the level variable in your game instance. You can use GetGameInstance and cast it to your custom GameInstance Class.

You could make an object variable in the game instance, on begin play in the level blueprint cast to the game instance and set the object variable to a self reference, then use that variable from the game instance to send the interface calls to the level blueprint. I do not know of any simpler way to communicate with the level bp but if someone else does please share.

Its the simplest (if you mean assigning a SELF LEVEL reference to a variable in game-instance). It can break quite easily though so be aware. Forget all the edge cases or gotchas here. If the level is ever renamed maybe or code is moved to a new level and so on. Here’s another solution…

The most reliable way that always works imho… Use the Level-BP to setup an Event-Dispatcher in advance (utilizing game-mode or wherever). Then link an Interface call back to game-mode to invoke the ED. That in turn will then call back into the Level-BP. Been using this for years and it has always worked (even if a level is renamed or code is migrated). Its pretty straightforward to setup ( if you’ve been using the engine for a bit). If not, there’s a legacy official YT tut titled ‘BP Comms’ iirc (Epic chap with red hair),. That will definitely help get you there.

The general consensus on here is don’t ever do anything in the Level-BP. But of course its helpful, especially when prototyping. But always ask yourself this… Can you migrate the code over to a separate BP and just drag that BP into the level, instead of creating code in the Level-BP. :wink:

Like this

( this assumes you only have one level open )

2 Likes

Epic are going to have to award you a ‘Community Hero’ second-dan black-belt :trophy:. As that is the simplest solution ever afaik. Tried to break it here, but couldn’t. It just keeps working! :stuck_out_tongue_winking_eye:. Even in older versions of UE. Using Get-All-Actors presumably can offer all Level-BP Interfaces too. Of course, there is a bit of bad news… You may have to go back in time and fix a few of your older posts that are now on the wrong side of history. :rofl: Anyway nice find dude… If your powers also extend to helping fix the new wonky captcha let us know…

1 Like

I don’t know when this became possible, actually… :thinking:

I must say, I got the idea, or something similar, from @Everynone.

1 Like

There’s a subsystem that can fetch it, too, me thinks. However, having to do it sounds like an issue with the architecture - you should never need to pull anything out of the LB.

3 Likes