Download

Game variable returns none

I’m trying to reference the MyGame blueprint, I looked up on how to refer to it here https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/BlueprintComms/index.html. This is what I came up with so far.

I have the GameVar variable set to “MyGame_C”, then trying to obtain the variable named “Obstacle Speed” defined as a float in “MyGame”. The blueprint compiles correctly, but the log shows “Error Accessed None ‘GameVar’ from node Construction Script in blueprint Barbed_Wire”. Barbed_Wire being the blueprint that is trying to reference MyGame_C. Am I missing something?

I also encounter this error often after playing in the editor for my “Beamed_Object” Variable.

I’m not 100% sure, but has GameVar been made public ( I see the eye icon is closed )? From the docs it says a variable needs to be made public to be updated by a different BP, but perhaps you also can’t read those variables if they’re still set to private? Just a thought :confused:

Thanks for the input guys, I’m still investigating this. I seem to have trouble declaring object variables to any object in the world. Thank you for pointing out the variable privacy, I made sure it was public but the issue is still there

I experienced the same, if you reference the blueprint directly, the variable generate this error.
If you pull the object through Exec node, the variable will be initialised - cast the object first and it will work.

This may have something to do with the order blueprints are created. Your Level will instance Game Mode, Pawn, Game State and so on. Accessing variable before it’s instantiated would generate an error like that. Someone please correct me if I’m wrong.

Everynone +1

Try to use “event begin play” https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/Events/index.html#eventbeginplay

I tried casting like you said via begin play and its still returning none. Used this as reference: https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/BlueprintComms/index.html#castingtoblueprinttypes

8d76a5d8c0f09ee2c242852a53452dfb926bc6b4.jpeg

Actually no. I have most of my variables Private (unless i need them in Details tab) and i can still acess and set values for them in another Blueprint.

Try this:

I see what you did there :slight_smile:
Casting works but casting from direct reference will not (not sure if it’s a bug or it is intended). It will not work with Game Mode, Game State and Controller Pawn and so on but, afaik, you can pull it off with a regular blueprint. You can access game framework with inbuilt getters, though.

This does not work:

But this does:

Essentially, I was more lucky when using those:

https://dl.dropboxusercontent.com/u/96577365/UE4/getters.jpg

Let us now if it helped.

Everynone, thanks for the pictures they were the key to helping me map it the way it needed. My problem is resolved!

What was the solution?

I’m late to this thread, but I can hopefully clear up some confusion on what you guys were experiencing with the game mode variable. When you make a variable in a blueprint of a basic type (like int, float, etc.) or of a struct, that variable represents one of those types, gets initialized to some default value, and you can get or set the value whenever you want. As an example, if you make an int variable, it’ll get a default value of zero if you don’t change it, and if you use the Get node on the variable, it’ll also be zero. When you make a variable that is of a type based off of “object” in the variable drop-down however (which the game mode is), the variable basically is acting as a “pointer” to a specific instance of an object of that type and its default value is to “point” to nothing until you tell it what its value should be.

This can be a bit of a confusing concept, but hopefully a simple example will make it clearer. Pretend we’re making a multiplayer game and for whatever reason we want our player to track which other character has damaged him last. To do that, we might make a variable of type “Character” in our blueprint who is always going to represent which character has done the most recent damage to the player. We don’t actually want this variable to create anything new (the other characters already exist!), we just want it to keep track of which existing character has done the most recent damage. Basically this variable will “point” to that character. When we first make the variable then, the default value is actually nothing at all. It’s not pointing to anything just yet, because we’ve not told it what you want it to point to. In the damage example, when the player takes damage, we’d then want to set the value of our variable to the character doing the damage, which would then make our variable point to that particular character and allow us to fetch it later with the Get node if we wanted.

This is basically why you were having problems with your game mode variable. The game mode is also based off of object, so when you make a game mode variable, it is also just a “pointer” to a particular instance of the game mode, which defaults to nothing until you point it to one. When you try to call blueprint nodes on an object variable that has nothing in it, you get the “access none” errors you were seeing. It’s basically telling you that you just tried to do some operation on a value that’s not filled in. The variable isn’t pointing to anything, so there’s nothing to actually do the operation on.

For game modes specifically, when you play your game, there is exactly one instance of the game mode created for you by the engine. The node you were calling “Get Game Mode” is explicitly returning you that particular instance, which is why it was valid to call operations on. Does this clear things up a little? I know this can be a little tricky to understand at first (and my super late night explanation might not be great). I can try to clarify some more when I’m slightly more awake if it’s still confusing :).

I understand that “accessed none” is blueprints’ graceful handling of wild pointers.
What I do not understand is the need for casting something like GameMode, since only 1 instance exists at a time anyway, as you pointed out. Should it not return the current game mode?

Also, I spawn an instance of the Actor and set the GameMode’s variable to this Actor. Is this the right way to do it then?

https://dl.dropboxusercontent.com/u/96577365/UE4/spawn.png

That “Get Game Mode” function is returning the current game mode instance, it just doesn’t explicitly know which subclass it is, other than it is based off of GameMode. If you want to get at functionality specific to your mode, you do have to do the cast there. It’s a similar situation to where if you make a variable of type actor and then assign it an instance of an actor subclass (like pawn or character). If you then “get” the variable, it’ll only know it as an actor until you cast it to the subclass type.

For your specific example, are you trying to spawn a particular actor and keep a reference to it on the game mode? If so, what you did looks basically correct at a glance. One thing to be mindful of is if you’re making a multiplayer/networked game, you’d probably also want to insert a “Switch Has Authority” node before the SpawnActor and make sure you’re only spawning the actor on the network authority. That’s kind of a different topic from what you asked about and I don’t know your exact scenario, but in networked games you want to make sure that important gameplay actors only spawn on the server. If you’re not doing a networked game, you don’t have to care about that at all and what you have is fine. If you are doing a networked game and this event graph is on an actor available on the client, just spawning the actor from Begin Play will actually try to spawn it on the server and the client directly, which is usually not what you want.

EDIT: I’m going to be away on a trip from tomorrow through the weekend, so I may not be able to follow-up on this thread again soon.

Your explanations (including multiplayer) are more than clear. Thank you very much for your time and enjoy the weekend.

I usually use Get all actors of class, then Get(a copy).
What comes out is the exact actor i want to talk to.

You know this thread is 4 years old…