I’m trying to use a c++ variable in another c++ class. I found several solutions for this in other forums, but unfortunately I can’t make them work.
I have class A with a variable float1. I already put it as a UPROPERTY in this class and included the whole class A in class B with #include. Now I want to use float1 in class B in another function.
You need a refference to a Instance of Class A the same as you do in BP. No refference == NoCommunication. The Include is there to tell your Compiler what Class A is and not giving you a specific Instance. You can have 1000 Class A Objects in your Level how can your Class B know from what Instance you want to get the float1 from?
Grab a C++ book before you proceed any further. You dont have a grasp at the fundamentals yet and you will struggle for no reasson if you try to make things work without knowing what you actually do, potentially breaking things you don´t instantly see or making yourself more work than you need.
Good Luck mate I hope you take my advise to Heart getting some Basic nailed first =)
Thank you for your response. Unfortunately I really don’t have the time to read a lot about basic stuff, this is not for fun but for an university project
I know I have to create an instance of the class A in class B and then cast from this to get functions or variables. But I don’t know the exact way.
I guess I have to go back looking at other examples.
Creating a Instance is one of many ways. You could get it from somewhere else like a Overlap Event as example. Or let it store a refference that is easy to reach like in GameInstance, GameMode and similar. But all of that comes down to what you want to do.
You have to take the time for essentials even if you got Time Pressure. Ask Proffessors and Friends from University to go over a couple essential things if there is no Time to read trough a Book.
If thats of any help for you here is a Video that covers some of those things in BP (including Cast, various ways to Communicate) all of those things in the Video apply to C++ aswell.
And you have the Ability to go to any Nodes C++ code if you are interested how its done behind the Scene (you can also call the exact same function from C++)
I only have to communicate between classes once in the whole project, that’s a lot of footage for this. However thank you, I will watch it.
Hi,
does your class define an UE actor? or which other type from UE?