Home Unreal Engine

Global variable

null
Offline / Send Message
Pinned
Evilbax null
Hi
I'm new with Unreal engine and I don't know how to use a global variable..
I just want to share a data(variable) between blueprints but I cant ,
so I've searched on a google got some tips and none of them worked..
  please help me..

Replies

  • Obscura
    Options
    Offline / Send Message
    Obscura grand marshal polycounter
    You can use "cast to" to communicate between blueprints. But if you google up blueprint communication, it should give you the explanations about this.
  • JonathanLambert
    Options
    Offline / Send Message
    JonathanLambert polycounter lvl 6
    Consider putting that variable in the game state. It's replicated and easily available to all of your blueprints. Like Obscura said, you can get the gamestate and cast it to your custom gamestate to get the variable. 
  • t_beaugelin
    Options
    Offline / Send Message
    Hey !
    You could also use a Blueprint Actor, which you would name Database or A_Database (A stand for "Actor"). You put all the global variables you need in this actor variable, make them available to all blueprints, and then use a "GetAllActorOfClass", and use a "Get" array. From there, drag the "Get" pin and call each of your variable !
  • Obscura
    Options
    Offline / Send Message
    Obscura grand marshal polycounter
    Hey !
    You could also use a Blueprint Actor, which you would name Database or A_Database (A stand for "Actor"). You put all the global variables you need in this actor variable, make them available to all blueprints, and then use a "GetAllActorOfClass", and use a "Get" array. From there, drag the "Get" pin and call each of your variable !
    Nah, then you should just store in like game instance. That stays even between levels, really good for carrying global stuff easily. Maybe game state too, I haven't tried that one.
  • Xendance
    Options
    Offline / Send Message
    Xendance polycounter lvl 7
    Game instance class is usually the best place to store global variables.

    Obscura said:
    You can use "cast to" to communicate between blueprints. But if you google up blueprint communication, it should give you the explanations about this.

    No, that's not the purpose of casting. Casting is another term for type coercion. 
    Imagine you had a variable with "animal" type. Then imagine you would have two sub classes of the animal type, cat and dog, in other words the animal would be the parent class of those two. Now, if you create a new instance of the cat class, you can set the animal type variable to point to the cat. It works because cat is an animal, or rather the type of the animal is the parent type of the cat. 

    But now if you try to access the animal variable you have lost its *concrete type*. There is no way for the program to know what the concrete type of the animal variable is, it could cat or it could be dog. Now, if you *know* that the concrete type is cat, you can then *cast* the animal variable to cat type. It will only work if the variable really is a cat. If you have stored a dog in the animal variable the cast won't work.
Sign In or Register to comment.