Download

Referencing Variables - Accessed None... - Please Explain

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:

This is the runtime error I get:

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.

How are you creating the reference to TeamSelectRef?

1 Like

Epic probably have a great tutorial on this. Better than any Indie can answer. Anyone at Epic with superpowers want to chime in? After all, what’s with the new support channels anyway? Is it just for Indies to help other Indies and do Epic’s job for them… Or is Epic up for helping out occasionally with an answer / reply from time to time. Lets find out… :stuck_out_tongue_winking_eye:

Meantime… There’s 100+ different answers for this. So which to give… There’s the low-hanging-fruit answer where you learn nothing (zero survival skills). That’s where you get warned about object references you forgot to setup. Then there’s the more robust CompSci answer, that gets you thinking about pointers and object creation and timing assumptions, and going down a rabbit hole you probably aren’t comfortable with yet. Then there’s the pragmatic answer. The one that gets you thinking about whether these errors are critical or mostly startup order related and resolve themselves… But will burn you later if you don’t understand the differences between PIE / Standalone / Packaged / Multiplayer and so on.

@Hourences @Hourences2 @VictorLerp @Amanda.Schade @Tina_Wisdom @ChrismMurray_EG @Stephen_Ellis @SkyeEden @KaitPaschall

1 Like

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


So to fix your problem: after you create your “TeamSelect” widget, set “TeamSelectREF” to that widget.

4 Likes

New signature?! :thinking:

2 Likes

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.

2 Likes

I appreciate your very thought out response.

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 fully understand now that I need to SET the reference, but even doing so … still broken.

1 Like

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.

Here:

You’re setting nothing to nothing.

Can you show the piece of code where you create the team select widget?

1 Like

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.

To demonstrate the problem trying to get game mode and SET game mode problem.

Cast to Top Down Down Mode first.

1 Like

I did try this, but there doesnt appear to be an object I can use for this…

Still get the error.

so, i moved the Cast to TopDownGameMode piece to the OnClicked event from the OnConstruct event. That appears to be working… testing…

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

1 Like

Cast from the game mode to top down game mode.

You just need a reference to the team select widget, which you get when you create it. No casting.