Variable with "actor as selected type" always returns null, why?

Ok so the variable Main is referencing an actor in the level. There is only one instance of that actor. Now I CAN read a variable “Counter Running” from it just fine but then I have to Set a variable I always get "Accessed none’ as an error message once I return to the editor. So I know that Accessed none means that the variable is Null and contains but how can it be null if I have just read from it? I basically can read a variable in that blueprint but not write…

Have you tried doing the same but using a standard “Cast to” class, with your variable selected instead of Self?

I’m assuming you can see the variable because you’ve marked it as public, but doing cast to, you can set/get anything within a class without any issues that i’m aware of.

You only selected the Type. You said you know what “NULL” means, so you should know that you have to fill the variable before using it. It’s weird that you can get any value of it. Fill the variable and only use it when it is not NULL or at least use an “IsValid” to make sure that you don’t use it when it’s NULL.

Your “There is only one instance of that actor” doesn’t do anything. There could also be 2 or 0. You need to get the reference of this one actor and save it (set) to the variable. Otherwise you will get the Error.

It’s weird, I’ve pointed that tree variable is not just an actor but the exact blueprint and yeah, I am able to retrieve the variables from it.

I ended up doing an array and just finding the instance at index 0 to retrieve that bp instance id. I still get an null error but now I’m able to get and set variables anyways. This looks like a bug now.

I have actually been trying to figure out the casting system for some time and the only object I was able to cast to was the player blueprint because when you cast to it, you can set target as “get first person character” at index 0 but for custom actor blueprints I have to set a target, which, come to think of it can really only be done with an array and reading the array for an object id.

ehm, no. The problem is that you didn’t understand the whole topic by now no offense.

Casting means, that you convert an Actor or what ever Class you got your fingers on, to another class. An example:

Your Player as well as an Enemy are from the “Actor” class. They are both childs of the same parent. Now you have an Overlap Event for a Trap that should only damage the Player, but not the Enemy.

The Overlap event reacts to every Actor, so as “OtherActor” you get the Overlapping unit as an Actor Class Instance. You have no idea if it is your Player or the Enemy. If you now try to cast that to the PlayerBlueprint Cast, the Cast will only succeed if the Player is really the one jumping into the Overlap. The Cast will fail for the Enemy.

Casting is also important to get specific variables that you’ve created in your Child Classes. Actor Class for example doesn’t know about Character specific variables. But if you cast it and the Actor is really a Character, you can access the Variables.

For your NULL or Accessed None problem:

A Pointer or Reference variable can be empty (NULL). If you create it and don’t fill it, it will be empty and you shouldn’t be able to use it like you want (and you will get the Accessed None Error). It doesn’t matter if you have an Instance of that class in your Game at the time. You will need to fill the Variable with a reference of that Actor. Either by overlap event, raycast or other things.

You COULD use “GetAllActorsOfClass” and get the 0 index of that array, but that is the worst thing to do! If the Actor is already placed in your scene before you start the game, you can get the reference by using the LevelBlueprint. It is the only Blueprint where you can get a direct reference by selecting the actor and rightclicking in the event graph.

Important classes like the PlayerCharacter can be accessed by “GetPlayerCharacter” at a specific index. The Number is only important if you have multiple players with a split screen or so. As long as you play online/lan or singleplayer, you can just take “0” for that.