Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.20
more ▼

asked Feb 10 '19 at 02:41 PM in C++ Programming

avatar image

6 1 2 4

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Feb 10 '19 at 04:05 PM

avatar image

11 1 2

avatar image L11777 Feb 10 '19 at 09:36 PM

Casting seems to work, but, at the same time, it's not really allowing me to do much, since I can't even do something like this (class type to be cast to can't be a variable's value, at least not an FName type one):

Cast<[name of class as a variable]>([class pointer variable]);

Would you be able to show me an example of how interface could be used for this? I'm having hard time understanding how this could be useful, or what interfaces are supposed to do exactly.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question