Good practices: store (or get) a reference of an element in the level

Hi!

I have a C++ class that represents an element inside the level (i.e. a table) and a pawn that works as a camera. My goal is to make zoom to that table.

By the way, that camera pawn is the default pawn in the game mode class.

To do the zoom I need to know the FTransform of the table because the pawn will do the zoom moving to the centre of the table. My problem here is how to get that FTransform.

I don’t know:

  1. if I can store a reference for the table in a GameMode class.

  2. Or pass a reference of that table to the pawn when it is instantiated.

  3. Or search for that table using the UGameplayStatics::GetAllActorsOfClass.

What do you think?

If you are only going to have the camera zoom in on that one table and that one table only, ever, you could GetActorOfClass and forget about everything else. Or use a tag.

If you’re going to have more elements the camera can lock onto, you will probably have a method to select those elements. That selection method will produce a desired reference.

  • it could be a line trace
  • it could be done via UI interaction
  • it could be #1 on your list where you hard reference an instance from the LB in the GM
  • it could #2 on your list
  • actors can detect clicks (although that would be somewhat awkward you’d then need to pass it on)
  • the player controller can detect clicks and return references (via its specialised trace)
  • you could use an overlap volume on the pawn and select something via proximity

In short, it’s currently unknown what the scope is; knowing it would make it easier to choose the right tool for the job. All of the above may be valid in the right circumstances. Some might be terrible.

Thank you for your answer.

There’ll be only one table and it’s going to be a multiplayer game.