Hello. I would like to have something like this in my game. When the player looks at an object, the name of object is displayed at UI, when player stops looking, it disapears. My question is… Do I need to shoot line trace every tick for this, or is there any easyer way?
Second question. Is shooting a line trace every tick bad for performance?
Do I need to shoot line trace every
tick for this, or is there any easyer
way?
If you want it to automatically pop up, then yes. You can have the player evoke it with an action instead; a.k.a. key press.
Is shooting a line trace every tick
bad for performance?
No, it’s not. 1 million actors doing 100s of traces every frame would be. You can give your actors tags, this will make it easier to weed out the unwanted elements so you do not need to cast every frame which is expensive-ish. Not in this case, though. If you’re dealing with a lot of objects of different classes, consider looking into interfaces - they simplify interactions like this (once you wrap your head around how interfaces work).
For something simple, you’re fine with a line-trace + cast.
To make it a tad more efficient, have a single widget (or widget component) belonging to the player display the target’s data rather than a widget for every object in the level.