Download

Cant Select an actor instance in Blueprint

I created a c++ class and declared a cemera actor variable
image

and then i created a Blueprint class for it and tried to assign an instance to it.

but when i select the camera instance it doesn’t appear to be selected (it remains “None”).
So What’s the problem here ?

TLDR: You can’t reference objects like this. The issue is that you are editing the gamemode actor class, not an instance of the gamemode actor (it hasn’t been spawned yet, since the game isn’t running). You are trying to reference an actor from a level, but the engine can’t tell what’s in the level until you actually spawn the object (the gamemode in this case). After spawning however, it will be able to say: “hey I see this camera actor, I’m gonna use it as my CameraActorView”.

If you give us a bit more context on what you are trying to do with this, I can be more specific, but for now, here’s some code that returns the first camera actor it finds. You can call this in BeginPlay() for example.

// .h
ACameraActor* FindFirstCamera();

// .cpp
ACameraActor* ALearnGameMode::FindFirstCamera()
{
	for (TObjectIterator<ACameraActor> It; It; ++It)
	{
		ACameraActor* CameraActor = *It;
		if (CameraActor)
		{
			// Found a camera actor!
			return CameraActor;
		}
	}

	UE_LOG(LogTemp, Error, TEXT("No camera actor found in the level."));
	return nullptr;
}

// set your variable in BeginPlay() for example
cameraActorView = GetFirstCamera();
1 Like

So i have to iterate all over instances of class type (“Camera”) to get the camera instance i want ?, isn’t that a bad prespective ? in large levels where you have a lot of camera instances ?