Is it possible to make pointer to a class without specifying class name?
I'm trying to create a trace to an object and check if it's a certain type of object via a variable. But the problem I see occurring is things going haywire if I define a class type to select, and then when tracing to an object with an invalid class type, it's going to glitch out really badly or even may be even crash. Probably not, but I'd rather be cautious.
Is there any way I can create a pointer to a class/object without defining the class type in the pointer? I'm having to define AActor* or UClass* which I don't really want to and doesn't exactly work for me. Specifying the type of the object I want to select however, again, could cause issues in the code.
On top of that, I need to be able to check if the class/object I'm selecting has a property and if that property has a certain value. Checking for value doesn't seem to be possible as VS instantly errors things out for me saying that AActor or UClass doesn't have the specified property type, so is what I'm trying to achieve even possible to do? Or is the error type of "pointer to incomplete class type not allowed" indicate exactly the fact that this is not possible? In which case, how could I handle this?
I found IsA() function, which could work for checking class type, but it doesn't seem to like to take a variable as a value and the documentation for this function doesn't tell me anything at all.
If you need more info on this, do let me know and I'll try to provide it.
asked Feb 10 '19 at 02:41 PM in C++ Programming
This is exactly the type of thing interfaces are great for. You can define an unreal interface and have these various objects implement it, then have your function accept a pointer to the interface type.
Alternatively, you could accept type AActor (or UObject if parameter might not be a type of actor), then use casting to the expected types within the function to see what type you are dealing with, and use reflection to check for and get the property you are looking for.
An interface would be much cleaner and simpler though.
answered Feb 10 '19 at 04:05 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here