All I need to do is to pick a new target and if it’s the same as the last target, pick again until it’s something different. So why isn’t this working?
Essentially I’m taking the current target and copying it to Previous Target. Then I’m getting a list of all of our goal locations. If this is zero, then I’m just setting my current target to zero and leaving. Otherwise, I’m getting a random number based on the number of entries in our array. If this isn’t the same as our previous target, then set the current target to it. However, if it IS the same as the previous target, then call the function again to pick another target.
This is my second rewrite to this function, and it still isn’t working. I know it’s real late, and I’m real tired, but where is my logic going wrong?? This should be VERY SIMPLE! So why is it not working?
Moved the Random Int to a variable to ensure that it’s the same. But noticed with my watches that my initial “set previous target index” with the current target index isn’t always changing the previous target index value. WTH?
This is just fighting me all the way. For the moment, decided to ditch going through random locations, and just cycle through each of my goal locations in sequence, but now (with an array size of 4) it’s only bouncing between 1 and three. And I’m really getting frustrated. NOTHING I am doing seems to be doing what I want! There’s got to be something else going on here. This is just too messed up. This is NOT a difficult thing to do at all. (Though, good call on the Random. Didn’t realize they worked that way in BP.) Basically NOW I’m taking my current index, incrementing it by one and moduloing it to the length of the array to keep it in range. Simple, right? So why is it only bouncing between 1 and 3?
WAIT! It’s acting like it’s getting called twice. Maybe that’s what’s going on here. Though, I’m only calling it once in my BP, the branch that calls it may be being called twice for some reason. That’s about the only explanation that I have.
Okay, I discovered it WAS being called twice during the same frame. Also, I changed the random to it’s own variable and used that for the math. Seems to be working just fine, now. If I’ve only got two goal orbs, my guardian now perfectly runs a scanning cycle only once at each one before moving on to the next.
Always try to do it right the first time. The less you have to touch something the more efficient you will be and the less chance you will cause errors down the line with something else. Just get it working and deal with it later is no where near a best practise.
Yeah, don’t take what I said too literally. I try to get everything working the best I can before I move on to something else, but in the end (or when I’m stuck on something else) I like to revisit older parts of my code to see if there’s anything that could have been done better or more efficiently. You can only work on one thing for so long before you start missing some obvious enhancement opportunities that you just didn’t see at the time. For now, everything is working for me the way it is. I find that sometimes recursive calls can be more effective than while loops in certain situations. (And I’ve also had many loops broken by UE4’s BPs so if I can avoid using them, I typically do–it’s become a trust issue.) But for this one, to me anyway, it’s po-TAY-toes, po-TAH-toes.