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.

Can you post some screenshots of your setup?

Left Click Part : Screenshot - 584a353f214be695de7da8b16cc23548 - Gyazo

Raycast1 : Screenshot - b086ebc6a99b8054fd5902f53964913c - Gyazo

Raycast2: Screenshot - e4e5994ceaf80c8654898695387ebd09 - Gyazo

ClickDelay: Screenshot - 19c92447466292edb87f29c196f07f45 - Gyazo

Variables : Screenshot - fa31b6fb11ae7c976f5f1d876bd66bb1 - Gyazo

Variables2 : Screenshot - fbaa1de57a6c532778fb51d6cfdaaad7 - Gyazo

Thats it, Ask for closer ones if needed.

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?

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?

Do something like this on your trace:

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.

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.

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

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

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

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

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?

FOR TREE 2

Raycast : Screenshot - 4af9f80407d7978c4eda82ec8708dcff - Gyazo

PlayerBlueprint1 : Screenshot - 5db57e9b048ef9bbe72ac2d16ffbce00 - Gyazo

PlayerBlueprint2 : Screenshot - d473cf1dbb1a2b70caedb826340112a3 - Gyazo

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.

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:

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.

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).

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:

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.

In your situation, I would recommend you looking into interfaces. I would also suggest adding in a print string on your Hit Hit actor to confirm what value is being returned.

Here is some relevant documentation for interfaces.
Implementing Blueprint Interfaces