Accessing C++ class (implemented as blueprint) variable by another class
I have a C++ class called
The PlaneClass is implemented as a blueprint class
What is the best way for the
I thought I could make the PlaneClass a singleton by using:
so that I can access these variables in the IntersectTest class using just this instance, for example:
but then I get an error :
asked Apr 24 '19 at 07:52 AM in C++ Programming
The error your seeing is because you haven't defined your static variable in your cpp, plus you're also trying to change the value of a const variable. If you change it to just be static rather than const static, and also make sure you define the variable in your cpp too.
However, this isn't the way I would do it. I've seen some issues around garbage collection and proper cleanup between sessions with this kind of strategy. Instead I'd either have the PlaneClass register itself OnBeginPlay with either a custom GameInstance class, or preferably some manager (e.g. PlaneManager) that is initialised and owned by the game instance class. This way any system in your game can access the plane (or multiple planes).
Note, as you've defined your class in C++, it'd be more efficient to actually perform the tick in the C++ class too. Invoking the blueprint tick every frame is relativly expensive, and what you're doing can be easily implemented into C++ for better performance.
answered Apr 24 '19 at 09:42 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here