I have a BP that I have drawn up - originally split apart across two BPs.
One was for a rock, another for a moving actor called Karlie.
Karlie wanders around randomly within a radius.
Each rock has (as part of the blueprint) an overlap sphere.
What I want to do is increase the value of a variable called rockaffinity the closer and longer Karlie is to the rock. Outside a certain radius there is to be no increase of affinity (when Karlie is outside the overlap sphere of the rock).
Below is the blueprint I have built up, however I cannot get the values of Affinity or Distance to register. The maths is there to make sure I always return a positive value (multiply by -1 twice).
When I separated out the Event actor begin overlap section in the bottom half of the screen and put it on the rock, reversing the ‘Other actor’ parameter, I was able to get a distance string to print out. At present all I get is zero no matter what I do.
I’m inclined to believe that the problem centres around the communications I’m using between blueprints. You’ll see references to SMRockBP C BP in the Event Graph. I thought (according to the documentation) that this was the way to reference variables in other blueprints.
I also wonder whether I should be doing some of this work in the level blueprint, but I want each individual Karlie I create to have their own values.
Here is the blueprint - any suggestions are welcome. Thank you in advance!
You dont have to do a double multiplication, you can simply use the Abs node to get the absolute value. Just plugin-in Abs at the output of Vector Length.
Another possible problem I notice is that At some point in Tick, you are calling ‘Set Disnatcetomesh’ located at the bottom (as part of Overlap event). However the input value for that node comes from the combination of nodes that sit close to Overlap node, who use ‘Other Actor’ in its calculation. However when this ‘Set Distancetorock’ is called from the top (tick event), that ‘Other Actor’ is undefined. So I think you better clone those nodes and attach ‘Sm_Rock_BP_C’ variable instead of ‘Other Actor’.
However a better method would be to call a function that calculates the distance between two Actors. This way you can reuse it in both event graphs.
Another ting to remeber is, the variable SM_Rock_BP_C could be null. You need to assign it to an instance at some point. The perfect location would be at ‘Event BeginOverlap’. Within the begin overlap, cast the OtherActor to SM_Rock_BP and if it succeeds, assign the casted ouput as value of variable SM_Rock_BP
Let me know if this fixes it. If not we can look further
In the end it is easier to do the work all in the one character.
I rebuilt it all from scratch with a new line of thinking, and instead I just set Karlie to do an onseepawn process instead (which if you check the box can also see actors), and then getting the class of the resource objects (rocks, trees, etc), matching whether the one seen to the blueprint class, then telling Karlie to approach the resource object she has seen, thus steadily building up her affinity to the items.
Using this way I could then start including an affinity for any other resource types she sees as she goes along, and she approaches other resources she discovers after she builds a full affinity for what she has. There’ll be some random searching, but priorities for house building and research, babymaking, etc all need to come along as well.