The single most difficult thing for me in learning Unreal Engine is the runtime error:
“Accessed None trying to read property Var”
I get so frustrated with this that I end up not doing anything for an entire day. I need to get past this lack of understanding so I can be better. Please help.
Details of current problem:
I have a TeamSelectCount int var in TeamSelect widget. This var is Instance Editable and Exposed on Spawn.
In the CharacterProfile widget I created a REF called TeamSelectREF to the TeamSelect widget. From that I pull the TeamSelectCount var as follows:
Blueprint Runtime Error: "Accessed None trying to read property TeamSelectREF". Blueprint: CharacterProfile_Widget Function: Execute Ubergraph Character Profile Widget Graph: EventGraph Node: Branch
Blueprint Runtime Error: "Attempted to assign to None". Blueprint: CharacterProfile_Widget Function: Execute Ubergraph Character Profile Widget Graph: ManipulateIntInternal Node: Set Integer (by ref)
These accssed none errors have dogged me since the start on various pieces of my project. I always find a work around, but I dont like that im using bandaids to solve a lack of knowledge issue.
A reference variable is just that: a reference, meaning it is not the object itself, but a reference to an object. Therefore, in order to use it, you need to set it to reference something, or else you will get an error if you try to access it because it isn’t referencing anything.
So an “Accessed None” error simply means you tried to access a reference that wasn’t set (i.e. nothing).
The rule is: if you have a get, you also need a set.
You can check if something is set by either checking if it is equal to “None” or checking if it is valid (which also checks if the object is not pending kill).
For these errors in particular, there is a small guide in the documentation here that touches on the “Accessed None” error as well as gives a few different examples of referencing actors. If you’re more of an audio learner this tutorial is very succinct and quick while still giving pretty insightful information. Keep in mind that both of these relate to your problem but aren’t a direct resolution to it, so it would be more for understanding why you’re getting the errors you are to hopefully help prevent some of them in the future.
@midgunner66 did an absolutely beautiful job of breaking down the concept of this error in particular. These resources will really only expand further on the same points, but it can be helpful seeing a problem tackled from multiple angles and with a few different examples.
As for learning about/from the runtime errors in general; they definitely can and do seem vague, especially whenever it comes to a new system you’re just diving into or have just started experimenting with. The best way to start with any of them is to break down the runtime error section by section and follow along in the blueprint. I’ve also personally found that building my C++ skills has helped exponentially with understanding how to work with blueprints directly as well.
After I had posted this I had watched countless videos on var references. 99% of those videos were about setting a reference to the character in one form or another, which is not what I am trying to do. Im trying to reference a var in another widget.
I did try moving things around. I moved the var to the game mode and then created a reference to that game mode. I still end up with the error:
I did see a video that explained timing… that potentially the variable/object didnt exist yet in the timeline and that delaying something could fix the issue. but thats not the case here. in fact, i actually moved the var to the game mode just to take this potential out of the equation.
The goal here is that every time the button that is created in the Create Character Button fuction increments the TeamSelectCount so it will limit the character count to 4. Problem is, I cant put that inside the button because the var would be local to that button, forcing me to put that var in the TeamSelect widget, or in the Game Mode like Im trying now.
By the way, I did actually try to Get Game Mode and link it to Set GameModeREF, but what I find is that GetGameMode, GetGameModeBase and GetTopDownGameMode will all return the game mode and I can print that, but the moment I try to call the VAR that is in the TopDownGameMode its not compatible with the GameModeREF.
Ok… so if i put the VAR in the game mode, the top solution works. However, I only want this var in memory during the character selection process which is part of the character select widget… i would prefer to have the VAR in the widget, not game mode. Problem is, I cant find an object to plug into the Cast to TeamSelect_Widget…
Here is the finished piece using the GameMode var instead of TeamSelect var. If anyone knows what object I would need to make the TeamSelect var work please let me know, but for now, at least I can move forward. Thank you all for your help.
Oh, and Id love to understand why setting game mode OnClicked worked, but not on OnConstruct.
If you ever have problems with assignments, right click on the output of the node and choose ‘promote to variable’. That will give you a variable of the correct type. I’m not saying that’s the solution here, but… ( maybe what Everynone say below ).