I'm stupid and i need help with references

ergh…
I’ve been trying and trying to reference diffrent variables from diffrent classes for a while now.
And i’ve figured out the part that “gets” the reference.
But i can’t understand/find how to SET it up so it doesn’t return empty. (I’m glad i figured out that part though)

So i get no error’s wich i at first didn’t understand.(i had similar experiences with other typs of stuff i tried to do)

If ANYONE :cry: could explain me the last part to set the reference. I don’t seem to get it…

Anyone? :frowning:

First of all, please don’t bump questions that are unanswered for less than 4 days. Otherwise this will clutter the AnswerHUB and other users can’t get their Questions answered.

For your problem:

A reference variable is a bit different to normal variables. For example an “int” variable always has an int value in it. For example a default 0.

But a reference variable can be empty (or NULL to be exact). So if you create one of them, you need to fill them somehow.

Most of the important classes can be get by standard nodes like “GetPlayerCharacter” and such things. For others you will need to find a few to get a reference.

For example you could save the reference (which is a spawned actor or a part of it) when spawning the actor you want to reference, by using the return value of the spawn node.

If it is something inside of your character, like a Camera Component, you can simply use “GetPlayerCharacter” and get the camera of it (maybe cast it to your CharacterBP if you have added the Camera in that BP class, otherwise other CharacterClass don’t know about this Camera).

If you want to interact with something in your scene, like a button or so, you can use overlap events or line traces and such things.

When you tell me what you want to achieve and where this “Camerara” is that you want to reference, i can try to tell you how you can get a reference to it, because for now, you only have an empty container (NULL) and nothing inside of it. (results in an “Accessed none” error if you use it).

I’m realy sorry for bumping that early! Also thank you for replying!

The “camerara” is just a Camera class i created from an actor. Wich holds the movement of the camera. Wich in turn is spawned in the Controller.

Ok so with what you said i managed to get it to work. For those interested, i did it like this:

Hope that’s the corect way to do it. And thank you for replying!

Na, no, don’t do it like this.

When spawning the Camera in the Controller, save it in a variable.

Then in your Widget, use “GetPlayerController” with index 0 (that’s the local first player one). Cast it to your PlayerController BP Class and get the camera variable from it.

Ok i understand. But, is this a “wrong” way to do it?
The reason why i ask is because i’ve stumbled on a bunch of moments where i want to get random variables from random stuff.

And this seems to be the way i can get it to work. Is it a slow way to do or am i going to get error’s in the future?

Btw, THANKS AGAIN for that quick reply!

GetAllActorsOfClass is a way too heavy node for something like this.
So yes, it is wrong. Although it is working, you should go for another way.

If you have single actors that you want to access during gameplay, spawn them in class that are easy to reach, like the playercontroller. Because you can always get your own PlayerController with the GetPlayerController node.

Aha i see, i thought spawning was literal and so that for most small things that for instance actor’s that are just “libraries” of variables have to be done in a diffrent way. Thanks again! You’ve helped alot to get me through this barier!!