Widget BP Accessed None When Trying to get Integer From Another BP

Hi, I am creating a turn based rpg and have a widget blueprint that acts as a selection for which move the player would like to use on the enemy. In the widget blueprint I am trying to decrement the enemy health by a certain value (determined by which move the player clicks on)

But the print string at the end to test the new health is displaying 0 every time and the output log displays the message: “Accessed None trying to read property EnemyBase”

The “Enemy Base” is an object reference to the blueprint class of the same name where the Enemy Health variable is set to 50.

Thanks in advance

Your reference isnt valid. Post a picture of how you are setting the reference to the enemy. Also to confim this put a print steing off the enemy base variable to show its display name. That will show you the exact instance of the enemy that you are referencing, it may be blank if its not set.

Please excuse my spellIng as im on my phone rght now.

Hi, I’m not sure what you mean by how I’m setting the reference, do you mean this??

246205-capture.png

OK I figured it out soon after you said I had an invalid reference, I used an object reference when I should have just used the “get all actors of class” node and found the right enemy from there, thanks for the help!

i probably wouldnt use the get all actors of class in this instance as its probably not the most performant. how are you selecting which enemy to target? are you clicking on them, or doing a aoe, or is it proximity based? knowing a bit more about your game and its systems would help to give you a specific method to use. for example if your clicking on the enemy then you could use that event to set the reference. or you could use a line trace to find a enemy in front of the character. in the case of aoe you could use a volume and get overlapping actors.

Agree, “get all actors” probably not the best here. Although just for future reference and to disseminate knowledge, I did some research on that node and apparently it is not as bad as people on forums and answerhub have made it out to be. Here is a link to someone who looked into the back end of that node and basically this is the important part I gathered

"The GetAllActorsFromClass Node uses a TActorIterator and ultimately ends up passing the specified class and through to GetObjectsOfClassThreadSafe, which is the workhorse that loops through the class-specific hashmaps stored in the FUObjectHashTables singleton."

Here is the link to the entire document

http://www.casualdistractiongames.com/single-post/2016/09/15/Inside-UE-Source-FUObjectHashTables-the-magic-behind-GetAllActorsWith

For sure, I agree there are better ways I was just sharing some info I discovered recently because any time anyone has mentioned the get all actors node the community (not you haha) goes crazy. Just thought I would add some new light to the topic.

its not that bad on its own, but in this case you would also need to filter and run calculations on the returned data to find the actor you need. this i believe would take more resources than other available methods such as a on click or something since you will probably have to be doing that anyway.

Oh, ok. I was going to have the player choose the enemy to attack using a button after selecting the move and pass the data through to a get node, would this not be the right way to do that? Can you suggest a more efficient way?

I am fairly new to blueprints so my bad if anything I say doesn’t make sense and/or isn’t a good way to do something

if theres not too many enemies you should be ok. where it really starts to get expensive is if you need to process the array of enemies once you have the info. though if you wanted to you could do the get all of class on begin play and make it into an array variable, then you would have the list of enemies and wouldnt have to recreate it everytime. with this method you would need a script where when a enemy dies you remove them from the array.

You know, you can probably use a node like “get hit result under cursor by object/ channel” and save yourself from having to store an array or use the “get all actors” node. So click the move on the widget, click the enemy in your world, break the hit result and cast to the enemy base BP or you can get fancy and use an interface.