Accessing variables between classes

I have a class called “smartCubeActor” which has a variable called “rowRank” which I want to modify but from a different class called “MyActor”

So what I tried to do so far is add, #include “smartCubeActor.h”, to MyActor.cpp

To access the rowRank variable, I’ve tried numerous things but nothing has worked so far. For example, I’ve tried creating an instance of smartCubeActor and that compiles fine but when I launch the game it immediately freezes. Any ideas?

Make sure you have both actors in spawned/ placed in the world.
Now determin how you want to obtain a pointer to the smartCube.
You can make a variable to hold the pointer in My Actor and use it like this.



if (MyActor)
    MyActor->SmartCubePtr = SmartCubeInWorld;

if (MyActor->SmartCubePtr)
{
    MyActor->SmartCubePtr->DoSomethingFunction();
}

is it possible to do this BEFORE both actors spawn in the world? The smartCubeActor contains a variable, let’s call it “R” and I want the R value to be different every time it spawns.

My end goal is to have a bunch of smartCubeActors spawned but each has a unique R value.

If you want there to be a random number generated for every smart cube.
Then in your smart cube constructor do something like this.


R = FMath::Rand();

hey thanks a lot for your help, I’m not sure how I got it working but all’s good now

Happy to help mate. :slight_smile: