Download

One blueprint different variables

Hello guys, i was wondering if it is possible to have one “House” blueprint, place two in my level, and each one would have different “Address” variable?

Thanks

Sure, if you have a Blueprint for your House and this Blueprint has a Variable “Address”, then you can spawn the House and set this variable for this specific one.
If you place the House Pre Runtime (before you play), you can also make the Variable “Editable” (where you also select the Type etc) and after you placed it,
you can select it in the Scene and change the Variable in the right Details Panel (might need to search for the Variable in all those other settings) for each
House.

Oh, many thanks, that really helped me! Any ideas how could i cast to specific of them based on that variable?

Edit: I think i got it, thanks for help!

Uh guys, I got another problem, how could i cast (call event) from one House to another specific one based on that variable? For example, player would input “11” and house would call event in another one with that number in Address variable.

If the houses aren’t dinamyc (I mean, there are an specific number of them always), then it is pretty easy.

Let make that “11” a integer variable. Then use a “swtich on int” and keep adding pins until the max house you have. And then follow all the nodes to their correct house.

I guess you will get how use it fast :slight_smile:

Yes, but the house is ONE blueprint, and i put multiple of them into the level, so how could i cast to specific one with switch?

You could use ‘Get All Actors of Class’, and then loop through until you find the house that has the “11” as it’s address, or you could do something like get a reference via a line trace, or an overlap if they walk near the house.

Good point JAmendxman3. With that way doesn’t matter how many houses are placed.

Yeah and maybe not. You shouldn’t use “GetAllActorsOfClass” when it is not needed. Do something else:

For example in your “GameState” Class (you can create your own and set it in the GameMode like you do with PlayerController etc), you create an Array of the House Class Type.
Then you create a CustomEvent in the GameState called “AddNewHouse”. It should have a parameter of the House Class Type too. This event just takes the Parameter and adds
it to the Array.

Now in your house, you create the BeginPlay Event and in it, you get the GameState (just search for “Get GameState”), cast it to your custom GameStateClass, call the new Event
you’ve created and pass the house (self) to it.

If you don’t get the Event stuff you can also just get the GameState in the House Blueprint and get the Array to call “Add” directly on it. The Event is just a bit cleaner.

With this all you Houses add themself to this array and you can get the Array over the GameState any time you want and iterate through it.
So the Array will only created ONCE and you can add a new Instance by just spawning a new house.

Way better and cleaner than using the GetAllActors node (:

Interesting approach. I like it.