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"

Local Variables HELP

I know the title isn't exactly specific but I don't know what to call it. So basically I am making a cutting tree script where you hit the tree with MsButton1 then I added a slight delay with 0.8 seconds so you cant spam it. Then it gives you wood. All this is done with raycast and left click. (Because I tried Vector Distance to but it didnt work so I will add that later.) This is all fine but if I go to one tree and click it (I made it print the health of the tree) it prints the health lets say to 2 but when I go to the other tree it goes to 1. I need every single tree different so it wont cut all trees down when I cut one. I know this is confusing so maybe read it again xD Plesae help I have been stuck on this for a little now and want to move on. If you have any questions Please ASK.

Product Version: UE 4.15
Tags:
more ▼

asked Mar 20 '17 at 08:21 PM in Blueprint Scripting

Purified Example gravatar image

Purified Example
1 1

Mosel3y gravatar image Mosel3y Mar 20 '17 at 08:24 PM

Can you post some screenshots of your setup?

Purified Example gravatar image Purified Example Mar 20 '17 at 08:40 PM

Honestly I don't really know how to set the value of actor variables. Usually I just hope for the best and somehow it works, probably cause it is the only thing I have in my scene. How do I set the value of tree?

Mosel3y gravatar image Mosel3y Mar 20 '17 at 08:48 PM

Do something like this on your trace:

alt text

Where the == node is, put your tree class instead. So on the trace, this will set your tree variable to reference the tree in your scene that the trace has hit. Meaning it's health will be reduced.

tree.png (136.6 kB)
tree.png (144.9 kB)
Purified Example gravatar image Purified Example Mar 20 '17 at 09:46 PM

Okay, sorry for the delay since last post but basically I was able to fix the problem I had with your help of course. But now I have a new problem. When I look at tree1 and click it it takes away health but when I look at tree2 it doesnt do anything. I am pretty sure it has to do with the left click event.

Mosel3y gravatar image Mosel3y Mar 20 '17 at 10:19 PM

What have you changed in your blueprint, have you set up what I posted in the screenshot above?

Purified Example gravatar image Purified Example Mar 20 '17 at 10:47 PM

Yeah, but I put Tree and tree2 instead of BP Door

Mosel3y gravatar image Mosel3y Mar 20 '17 at 10:49 PM

What is tree2? Could you post a screenshot of that section of your blueprint?

Purified Example gravatar image Purified Example Mar 20 '17 at 10:59 PM

I am trying to make a blueprint that can support multiple trees thats where tree2 comes in. I duplicated the blueprint script and named it tree2 then placed the tree in the scene

Mosel3y gravatar image Mosel3y Mar 20 '17 at 11:03 PM

You don't need to duplicate the blueprint if it's going to be the same as Tree1. You can add as many trees as you want in your scene, and your player character just needs to reference the specific one that you want to chop down. That is what the trace is doing: setting the value of Tree to the one you want to chop.You only need one blueprint class for Tree to do that, and one reference to Tree in your player class.

Or do you have multiple types of tree blueprints that you want to have in your scene?

Purified Example gravatar image Purified Example Mar 20 '17 at 11:08 PM

I tried to delete bp tree 2 and just put multiple tree blueprints in the scene but the var treeHealth is still global. If I look at one object and hit it it takes one health. If I stop and look at a different tree and hit it the health carries where it left off.

Mosel3y gravatar image Mosel3y Mar 20 '17 at 11:34 PM

Why do you have that global tree health variable, you only need the health value from the tree. That is the variable you should be printing. Like: alt text

Also, on your trace you are checking for Tree2 on the == node, but on left click you are casting to Tree so it will fail. Forget about tree2 for now, just focus on getting it working on the tree class. Change the == on the cast to be Tree.

tree2.png (44.9 kB)
Purified Example gravatar image Purified Example Mar 20 '17 at 11:43 PM

The blueprint that you provided wouldn't work in my sense. I am needing 2 branches. 1 for if LookingAtTree and 2 for if CanHit.Then I need it to set Target health to target health - 1. (--treeHealth).

Mosel3y gravatar image Mosel3y Mar 21 '17 at 12:08 AM

Ok, I thought you were doing all this in your character, so the above won't work. Apologies for the confusion.

Here is how I would do this, in your Character class:

alt text

To get the LineTrace lik that, just right-click the OutHit and click Split Struct Pin.

Remove the trace from the Tree, it doesn't need anything to do this except an Int for health.

treetrace.png (319.1 kB)
baraa7698 gravatar image baraa7698 Mar 21 '17 at 01:58 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 01:58 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 01:58 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 01:58 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 01:59 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 01:59 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 01:59 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 01:59 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 01:59 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 01:59 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:00 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:01 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:01 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:01 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:01 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:01 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:01 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:02 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:02 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:02 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:02 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:02 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:02 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:02 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:02 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:02 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:03 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:03 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:03 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:03 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:03 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:03 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:03 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:03 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:03 AM

v..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:03 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:04 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:04 AM

v..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:04 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:04 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:04 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:04 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:04 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:04 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:04 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:04 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:05 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:05 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:07 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:07 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:07 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:07 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:08 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:08 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:08 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:08 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:08 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:08 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:08 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:09 AM

..........

baraa7698 gravatar image baraa7698 Mar 21 '17 at 02:09 AM

..........

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Where do you set the value of Tree? You have multiple trees in your scene I suppose, but it looks you are only modifying the health of that single tree.

On your trace, you should be setting the value of your Tree variable to the hit actor (provided it's a tree). Are you doing anything like that?

more ▼

answered Mar 20 '17 at 08:36 PM

Mosel3y gravatar image

Mosel3y
1.3k 43 12 49

(comments are locked)
10|2000 characters needed characters left
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