Announcement

Collapse
No announcement yet.

Is it possible to return a custom string or variable from a line trace ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Is it possible to return a custom string or variable from a line trace ?

    With LineTrace I seem to be forced to use "get object name" to return or identify a certain object. "get object name" returns the objects ID wich can be miles long within in an actor. I can´t seem to change an objects ID by myself. In the tutorials they use "get display name" for line tracing. But this only works in the editor. It seems to return nothing in a final build. So my question is. Is it somehow possible to give an actor or a component of an actor some sort of variable (preferably string or int) wich is returned by the linetrace ? I´ve seen there are trace channels but I can´t seem to find any good ressource to show me how to setup custom trace channels other than visibility or camera. I´m also not sure if this is what I´m looking for.

    #2
    If you want to identify a certain, unique actor, you may use Tags. Every Actor has an array of optional tags and you can use them to identify a certain actor.

    However, if you want to distinguish between actor types (i.e. enemy and player), you may want to use casting and other OOP-related techniques like Interfaces.

    Comment


      #3
      You can cast the result of the Other Object from the linetrace to whatever you want.

      If the cast succeeds, you can call any function or property on that class.

      e.g Create a new BP class MyHero.
      Add Name property.
      Give property value.
      Shoot it with LineTrace.
      Cast to MyHero
      Read Property.
      https://www.casualdistractiongames.com

      Comment


        #4
        Originally posted by OptimisticMonkey View Post
        You can cast the result of the Other Object from the linetrace to whatever you want.

        If the cast succeeds, you can call any function or property on that class.

        e.g Create a new BP class MyHero.
        Add Name property.
        Give property value.
        Shoot it with LineTrace.
        Cast to MyHero
        Read Property.
        Let me be a bit more specific. Basically I got all of this working. My problem is the identification of a certain object once it gets hit by a linetrace. For the moment I simply compare (string boolean) the hit result with a string variable that contains the exact result the "get object name" returns once the linetrace hits the object. Well I setup a datastructure wich contains all of the strings I need to compare. But I think the process is not very elegant as it´s a huge listing. If I could set some sort of variable to an actor. Let´s say something like Menu1Button1 and get those variable returned by the line trace I could pretty much automate this process. After all I´m looking for other ways to specifically identify an object by linetrace.

        Maybe what Raildex_ wrote about those Tags is what I´m looking for. I´ve looked into some ressources about tags and I think I understand what they do, but is there a way to return a tag of a specific object from a linetrace ?

        Comment


          #5
          Originally posted by netfrag-sam View Post
          Maybe what Raildex_ wrote about those Tags is what I´m looking for. I´ve looked into some ressources about tags and I think I understand what they do, but is there a way to return a tag of a specific object from a linetrace ?
          It's all a matter how you structure your code.
          Every Actor has a function "Actor Has Tag" which has your specific String as an input and returns a boolean (true = has Tag)
          You may also use interfaces, which return your specific String and you simply call the Interface function on linetrace hit. (Interfaces are easier to maintain than Tags)
          Interfaces also increase your flexibility.

          Comment

          Working...
          X