How do you get a variable from the level blueprint?

TL;DR:

How do I get a certain variable (float) from the Level Blueprint?

Everytime my AI spawns, the Level Blueprint sets the variable ‘EnemyAmount’ ++1

But now I want my AI Blueprint to substract “1” from ‘EnemyAmount’ everytime one of my enemies (AI) dies:

… → Destroy Actor → Set ‘EnemyAmount’ (-1)

But the variable EnemyAmount isn’t in the AI Blueprint and I can’t reach it with ‘Context Sensitive’ unchecked.

Why dont you set it in Game Instance or Game State BP’s?

I don’t know what that means :c

Create the EnemyAmount variable in your Game Instance blueprint(create one in content browser if you dont have it already, and then set it as your game instance in Project Settings) Then you can get/set that variable from any other BP by Get Game Instance > Casto to yourgameinstance > Get/Set EnemyAmount.

Well, my gameinstance is already there but in c++, i only have a blueprint project. If i create a new gameinstance and use that, do i get errors?

You mean it is using the default game instance currently, i think? If thats the case then yeah, just create a new game instance BP in content browser, set is as your project’s game instance in project settings and use that.

Thanks for your answer, but I have a not so important question:

If I use another GameInstance BP, doesn’t that have a huge lack of functions? Because there already is one GI BP used.

Thank you again

EDIT: I noticed that I need a reference, do you know how I can refer to the gameinstance ? Screenshot by Lightshot
I already have a Reference to my gameinstance but even if I use it, I need another reference or something like that

There wont be any difference between the empty default GI BP and the one you will create in the content browser. And yes, you’ll only create the variables and use the game instance to pass those values between other BP’s.

Right click anywhere in the graph and then Get Game Instance > then drag from the blue pin and Cast to Yourgameinstance > and finally get/set your variable.

Could you answer my edit too. please?

Thanks that worked. Do you know why my AI won’t die sometimes even though the Health == 0 mark was hit?

Can it bug sometimes?

I think I got it but I don’t know how it worked, I just connected the ‘Destroy Actor’ with the (if) AIHealth == 0 node.

Basically it’s in the same function but it wasn’t earlier… I don’t know… somehow it worked

No idea. You should post a new question regarding that and make sure you provide some screenshots as well.