Identifying object type in a line trace

Hey guys I’m in the middle of blueprinting my “use” function and I’ve gotten to the point where I have a line trace hitting stuff in the environment. My question is: Is there a way to group actors in a way that is identifiable in the blue prints? So for example a bool that would flip to true if the camera is looking at the object represented in the bool (IsLadder, IsKey, IsNPC.) I want when I hit the use key for it to check to see what is being looked at and call the appropriate function. I just dont know how to define what the line trace is looking at beyond using the name of the object. Is there a recommended way to classify the object in view? I appreciate you guys helping me :slight_smile:

You could add a Blueprint Interface and have all relevant objects implement it.

Declare your function (e.g. UseObject) in the Interface and define the behavior of said function in all classes implementing it. In your trace, you can call UseObject (message) on the HitActor (if valid) and the objects will take care of everything themselves. The trace doesn’t even have to know what type of object was hit, though I guess the Interface function could return the class type if you need it.

That’s what I did in response to clicking on an object, which leads to different actions when executed on a NPC or an interaction object, and it works great. The only minor issue I had was that the interface function needs to have an output value (I used a “success” boolean) to appear in the list of implementable functions in the Blueprint implementing the interface.

Thanks for the quick response! I’ve never used Blueprint Interfaces, I’ll read up and see if i can implement it. :slight_smile: If i understand correctly the actual function of the object would occur inside of its blueprint right? So ladder for example would be referenced to the “Use” blueprint interface and would do all of the actions required of a ladder in its blueprint. Right? Simply using the interface as… well an interface (hehehe) between the object and the Character “Using” it.

Pretty much, yes.

I don’t have access to my project right now, but I did the following:

  1. Create a Blueprint Interface and declare an OnClick function
  2. Have both my Character and Item implement the interface
  3. In my PlayerController after the trace, I called OnClick with the HitActor as target
  4. For the Character, OnClick handled selecting characters
  5. For the Item, OnClick handles pickup (if the currently selected character is in range)