Download

How to determine the class of an object detected in a Trace

Probably a noob question by a noob!

I am trying to set up a simple interactive archviz style UI in blueprints. It is working but I am not happy with the implementation as it seems horribly inefficient,

I have a line-trace using a custom coillision channel attached to my character that fires every 0.1s on a timer and sends valid hit objects (of unspecified type) to a handler…thus…I have created a blueprint parent class handler that receives a reference object from the trace stored as a local variable and has basic common functionality I want available to all my interaction items, which are then all subclasses of this handler class. (such as chair, table, door)

Each subclassed actor can then have a different set of interaction widgets, but as these all have some basic common functionality, I have a parent widget which contains only common interaction functions (ie key press defaults) , which is then subclassed to provide more specific design element UI (texts, buttons, sliders) unique to the object in question.

When the object reference is sent to the actor subclasses from the trace, I then load up an assigned widget subclass and pass it the object reference so it can display some basic data like the name of the object, which can be achieved using <get display name>, but for the life of me, I cant get the type of subclass actor from the hit object reference even if I cast to my parent actor class.

Surely there is some way to asses what type of subclass the reference object contains?

Im thinking of functions in other languages such as isA, or isInstance of

Also if I pass the referrnce object, why do I have to still cast to my subclass actor and run a select all actors in scene to get the specific actor…surely the reference object can only ever be one of these subcasssed actors, but I cant get to it any other way than setting an isActive flag on the parent class and checking for this over every object in the scene.

Seems ineffiecent, and has potential for a nasty bug if more than one actor is ever active (although I have taken steps to ensure this cant happen)

Look into blueprint interfaces (code interfaces not GUI), and blueprintable components.

What i did several times, is blueprintable component with blueprint interface. Then you drop (add) such component to light or static mesh or almost any actor. (does not work with CSG geometry brushes). When you line trace actor, you check if it has your blueprintable component as child. Then you can send event to that component, or change its variable, etc.

Benefits:

  • code only in blueprintable component, not in every type of light , mesh sound etc.
  • easy to drop it on almost any actor in editor and have its functionality added.
  • no need for classes and casting to, you find component and cast to it, or you use blueprint interface inside component, no casting required.
    Cons:
  • quite complicated code to get to component and communicate from it to parent object (then you have some of that casting back)
  • hard to grasp all that, but you are already past that problem (from what i read in op)

i will look into that as my next learning task, but i think there must surely be a way to determine what kind of class or subclass an object reference contains?

do i have to attempt casts to all my subclasses in a serial chain until one doesnt fail? that seems awful.

ive got around it by putting a string variable in my superclass that is set by the subclass constructor to identify itself, but surely thereis a more fundamental way to get this info?

so i rewrote my whole project after i discovered “expose on spawn” when creating a widget and now its not even an issue. i simply pass my superclass widget a reference to my acive object.