r/unrealengine Dec 05 '24

Line Trace Component hitting parent instead of component Solved

I have a line trace component block being called every tick to highlight a component when you're looking at it. When this line trace is called though, it doesn't highlight when hitting the component, but it does when hitting the parent. The trace is following the right path, just not hitting the component

2 Upvotes

2

u/PokeyTradrrr Dec 05 '24

Can you share some screenshots of the line trace code(or blueprint) and the collision settings for the component?

2

u/stcifttm Dec 05 '24

For the line trace:

https://preview.redd.it/053rse7nhx4e1.png?width=1069&format=png&auto=webp&s=b9ff2d691f12a42cb4d0ee46eb45cb7834f38042

The component collision preset is set to BlockAll, and uses complex collision as simple

2

u/PokeyTradrrr Dec 05 '24

You are using line trace component....Is the component you are trying to highlight the "Postal Ship Control Panel" ?

2

u/stcifttm Dec 05 '24

Yes

2

u/PokeyTradrrr Dec 05 '24

Ok, I'm a little confused. This code is intended to only work for 1 very specific component? Not intended to be a generic "interact" system? And it's working for a different component?

Can you show where the postal ship reference is set?

2

u/stcifttm Dec 05 '24

This code is in the postal ship actor, and so is the component. I'm trying to have different parts of the ship be interactable without having different actors.

6

u/PokeyTradrrr Dec 05 '24

Ok now we're getting somewhere, I think you would be best served rethinking this into something more generic and extendable. This is going to seem like a lot, but it will be the type of system you can utilize for anything at all in the future.

1) Project settings > collision - add a new trace channel called "Interact." Set the default to ignore.

2) Move the interaction code to the player pawn (or a new component that the player pawn owns).

3) Create a new interface asset "BPI_Interact"

4) in the new interface, add two functions; "CanInteract" which takes a SceneComponent and returns a boolean, and "Interact" which takes a SceneComponent.

5) In your ship actor, implement the new interface (its in class settings). For CanInteract, return true (at least for now) and do your highlight logic here. For Interact, do your interact logic. In both interface function implementations compare the input SceneComponent with your interactable components (eg, ship console) to determine which one is looked at.

6) again in your ship actor, change the collision of any components you need to Interact with to custom, and set your new Interact channel to Block.

7) Switch to using "Line Trace By Channel" and set the channel to the trace channel to your newly created type "Interact."

8) if the line trace hits something, use the new interface function, "CanInteract (Message)" targeting the line trace hit actor, and for the input scene component, feed it the hit component.

This system will allow each interacted actor to handle its own interaction action, including differences for different targeted components. As I said, it might feel like a big undertaking, but it will be very much worth it once you have it up and running.

I hope this helps, good luck!

2

u/stcifttm Dec 05 '24

Thanks so much, this worked

2

u/PokeyTradrrr Dec 05 '24

That was fast, glad I could help :)

1

u/AutoModerator Dec 05 '24

If you are looking for help, don‘t forget to check out the official Unreal Engine forums or Unreal Slackers for a community run discord server!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.