Array_Add doesn't compile when TArray is declared as TArray<CustomClass*> in C++

Hello, I have run across a strange issue which occurs in C++ and not in Blueprints.

I am declaring a TArray in my .h file like this: TArray<CustomClass*> TestArray;
Then in my .cpp file, I try to add an element using the Array_Add function like this: UKismetArrayLibrary::Array_Add(TestArray, ClassToAdd);
However, it always throws a compile error saying it can’t convert an int32 to a pointer. When I try to do the same in Blueprints, there isn’t any problem and everything works like I would expect it to. I am quite new to Unreal so this might seem like a dumb question, but I really can’t figure out why it’s doing this :slight_smile: Even tried using the angle brackets with the CustomClass* in them after the Array_Add and the input array, but it never worked.

1 Like
  1. Kismet libraries are most of all used for blueprints. If you are going to use them in C++, you might as well stay with the blueprints. For proper C++ code, look inside the kismet library and see what it does, and try doing that instead of calling a Kismet function.

  2. If you read the description of Array_Add, you’ll see “These are never actually called… Call the Generic equivalent instead”.

  3. Anyway, just call TestArray.Add(ClassToAdd); and you’ll be fine.

1 Like

Oh, I don’t know how I could have missed that…

Didn’t know that, will do next time : )

Thanks for the response and advice, as I said I am new to Unreal, so sorry if it seems like a dumb question but I really couldn’t figure it out.