How do I access a UPROPERTY variable in C++ without Instantiation?

I have a C++ class (PlayerPawn.cpp) that has a private UPROPERTY variable. I then have a blueprint class (BP_PlayerPawn) that is based on PlayerPawn.cpp.

Now, I also have another C++ class (GameModeBase.cpp), from which I’m trying to access the UPROPERTY variable explicitly from BP_PlayerPawn, without instantiating the class.

I’ve tried to do some reserach, but no luck. Any form of help would be greatly appreciated!

If you don’t instantiate the class, that variable will always be the same, why do you want to access it? Just create the same variable in your game mode and use it.

1 Like

Yeah I just realized how much of a silly mistake this is, my brain is a bit fryed up from all the studies I’ve been doing the past hours haha.

And I just realized that you’re the same person that answered the previous question, thanks for all the help!

You can use static variables but not with UPROPERTY

You actually can do this Get Default Object of Class - #9 by John_Vanderbeck

However, your game mode is actually instantiated (at least in standalone or on a server in network modes), so you should be able to access that instance also.

Why you want to do it is a perfectly valid question, there’s not a lot of good use for this sort of thing.

1 Like

Hey, I actually did realize eventually that this is completely avoidable.

I’m happy to hear that Get Default Object of Class is able to accomplish this nevertheless, thanks!

1 Like