Download

Setting up default variables in C++

Hello,
I’ve been seraching this for a quiet long time, and I can’t find the answer.

Let’s say, I have two static cameras in scene.
I have a gamemode (C++) and these variables


UPROPERTY(EditAnywhere, Category=Camera)
ACameraActor *ActionCamera1;
UPROPERTY(EditAnywhere, Category=Camera)
ACameraActor *ActionCamera2;

How do I assign my two static cameras into these variables WITHOUT using Blueprints ? I’d like to learn this with C++ only. Is there an effective way to do ? I know one way is to iterate through every actor in constructor, but that doesn’t seem like effective way.
Thanks you.

Any number of ways. Have the Camera Actor’s register/unregister themselves to your GameMode when they are created/destroyed, then have your game mode pick which to use. Or just do the TActorIterator but pass in ACameraActor to limit it to just Cameras.

The registration model is more performant, but either could be fine depending on the needs of your game.