x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do I change a variable that is in a different blueprint?

I have a variable called 'max zombies' which is located inside an enemy spawner which I have created. I need to be able to change this variable from a blueprint located in my character... I need the 'max zombie' variable' to update every time I pick something up which I also have a variable for... the issue is that these 2 variables are not in the same blueprint so I am having trouble.

The 'max zombie' variable is public, I can cast to the enemy spawner from my character blueprint, for the target of the enemy spawner cast I have used 'self', after the cast I simply have 'max zombie' is equal to my other variable... however thisalt text setup simply does not work.

I have attached a screenshot and hope someone can help with this.

Thanks.

Product Version: UE 4.13
Tags:
variables.png (293.0 kB)
more ▼

asked Oct 16 '16 at 12:47 AM in Blueprint Scripting

avatar image

Tommow
15 13 17 19

avatar image MacDx Oct 16 '16 at 01:58 AM

Ok so just I understand the system you have here. You have a character blueprint which is Liam_CH I assume. Then you have a spawner object that has a max zombie variable that you want to change. And you have a pick up object. Now you want to set the max zombie variable in your spawner object when you get the pick up object, am I right?

avatar image Tommow Oct 16 '16 at 02:00 AM

You are correct. That is exactly what I want.

avatar image MacDx Oct 16 '16 at 02:03 AM

Ok give a few minutes to show you an example of how to do it

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

If I understand right, you have to change the self referrence to a reference to the spawner, depending on your game this can be achieved in different ways. You can "get all actors of class" and then cast to all of these if there are more than one. This is the easiest solution, but it depends on your game if it is the best for performance, but it shouldn't matter if you don't have more than around a thousand spawners :).

What it is doing now, is basically telling it self that it has to change the variable, not the spawner. This could also cause a loop, if the variable changes every time the variable changes in the LiamBP. Could cause a crash.

more ▼

answered Oct 16 '16 at 02:20 AM

avatar image

Lexyth
133 6 10 18

avatar image Tommow Oct 16 '16 at 02:24 AM

Thanks for the reply... I can not connect the output of the 'get all actors of class' to 'cast to' node... the output is an array and the input is an object so they simply do not connect up... any ideas what I am doing wrong?

avatar image Lexyth Oct 16 '16 at 02:27 AM

You have to get every actor from the array via an For each loop plug the array in the left side and on the right you get an actor and an integer. you probably just need the actor reference to plug into the cast to node and that into the set max zombie node like above, but make sure that if you want to add something behind, you have to get it from the "Complete" execution on the for each loop otherwise it will integrate it in the looped actions.

avatar image Tommow Oct 16 '16 at 02:30 AM

I dont understand what that means...

avatar image Lexyth Oct 16 '16 at 02:35 AM

i'll try to setup a better explanation

avatar image Lexyth Oct 16 '16 at 02:43 AM

You have the set Points, then you connect that execution pin to the for loop. then that execution pin (loop body) to the cast to node and then stop. dont connect the max zombie yet. then you connect the arry node from the for each loop to the get all actor from class array node. Then you connect the array element from the for Each loop in the cast to node. and then you can set max zombie from the blue node to get the right blueprint class that contains that variable.

avatar image Tommow Oct 16 '16 at 02:20 PM

I still dont understand... I thought I was calling the dispatcher in the add points function?

Sorry that I do not understand I am still new to ue4 :/

avatar image Lexyth Oct 16 '16 at 09:17 PM

think you are confusing our two answers :) The dispatcher solution was give by MacDX. My solution is different. I'll make a Picture of how us have to set my solution up, so you have both ways. It'll take some time.

avatar image Lexyth Oct 16 '16 at 09:38 PM

This should be very clear. Had to make it a bit smaller to fit in the screen :)alt text

pickup spawner.png (304.8 kB)
avatar image Lexyth Oct 17 '16 at 10:56 PM

Also could you please set this as resolved if it could fix your problem, so that other people know that there is a solution.

avatar image Lexyth Oct 18 '16 at 02:17 AM

My answer is the easy one, while MacDX is probably better for performance, if you have many Actors. Just to let you know. :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

There are various ways to do it. You could have a direct reference to your spawner in every pick up object or inside your character blueprint. You could also use the get all actors of class node and use it to look for your spawner class, in your pick up object when the overlap or hit event is triggered. And finally, the solution that I like the most for this type of cases is an event dispatcher.

An event dispatcher allows you to send a message to any class that you want when something happens and you can pass any info into this message. So here we go.

First go to your character class. This is the class that will be broadcasting the message.

Add an event dispatcher with the + button in the event dispatcher tab. Name it what you want. Now make a new function and drag the dispatcher to the graph. A little menu will appear. Chose "call" and connect it in the function. Like this:

alt text

Now go to your zombie spawner blueprint

On begin play do this. Get your character cast it to your own Character class (Liam_CH) and drag from the reference pin in the Cast and search for assign "name of your event dispatcher". Now when you choose this action it should create an event automatically for you, in this event is where you set the max zombies variable to whatever you want.

alt text

Finally go to your pick up object.

In this object I'm pretty sure you have an overlap or hit event for when the player touches it. So from this event drag from the other actor pin, which is a reference to your player, cast it to your Character class and from this call the function that you created it that calls the event dispatcher. Like this.

alt text

So now, everytime your character picks up an object of this type it will send a message to every zombie spawner so they can do something about it.

Tell me if you have any questions!

dispatcher.png (147.9 kB)
dispatcher2.png (292.1 kB)
dispatcher3.png (233.8 kB)
more ▼

answered Oct 16 '16 at 02:36 AM

avatar image

MacDx
600 17 9 33

avatar image Tommow Oct 16 '16 at 03:30 AM

I have set all those nodes up... but where am I makign the change to the variable? in what blueprint?

avatar image Tommow Oct 16 '16 at 03:45 AM

For every pickup I need 1 adding to 'max zombies'... but I do not know where to add this.

avatar image MacDx Oct 16 '16 at 04:07 AM

In the second image, the zombie spawner blueprint

avatar image MacDx Oct 16 '16 at 04:10 AM

Do it like this alt text

That ++ is called an increment node. It adds one to your variable

dispatcher4.png (102.6 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question