Cast To without overlap

Hi all. Can I access data from another object without using an overlap? For example, there is a character and there is a cube, the character constantly receives the coordinates of the cube regardless of where the character is located without using an overlap. The answer was not found in open sources, so I write here…

This isn’t an easy thing to answer because there are many ways to “Find” an object, or hold on to a reference of that object. Including:

  • Player spawns the Cube and holds on to a reference to that Cube (works if the Player knows where to spawn the cube).
  • You place both the Cube and Player in a level editor and assign the reference to the Cube on the Player there (works as long as the objects aren’t dynamically spawned).
  • The Cube registers itself with the Player when the Player logs in (pretty sure there’s some events internally for this).
  • The Cube registers itself with some Subsystem that the Player queries for information (probably the way I would go).
  • You use a TObjectIterator to find all the types of classes that the Cube uses (and hopefully the cube has it’s own class).
  • Using Queries / Sweeps / Raycasts to find the object using the Physics scene.

So, the answer to your question is “Yes”, but it’s up to you to decide what is the best way to hold on to that object depending on what you are trying to do.

Thank you very much! Tell me please, is there an elegant way for the character to move on the surface of the object and not fall off it?

Not really. The Character Movement Component has a way to avoid falling off by basically doing a raycast in front of the player, if it doesn’t hit anything, then it doesn’t let the player move.

Sure You can do that with number of different ways.
if this is only needed for a small scale feature or game you can use add a new variable of Type Actor into your character class and before starting PIE or building you can just assign the cube Actor to the character.

now what if the Cube Actor does not exist but is spawned in game? well then you can just use a Manager Class, when ever a cube is spawned it registers itself to the manager, now you can have the character class to call on manager and get the cube Actor.