There’s a data structure in UE4 that I need something from. Only its a UStruct currently and I really need to add some functions to it. Only UStructs in UE4 aren’t like normal C++ structs where you can simply add methods. So I’m wondering what the difference is between a UStruct and a UClass and what the overhead would be from changing it from struct to class? Does anyone know?
The problem I’ve got is with FAIStimulus in AIPerceptionTypes.h in that I need to be able to get sense type so I want to add a UFunction to get the type of stimulus so I can get it from blueprint. I also want to be able to call IsActive method on it from blueprint too.
I guess the other question would be if there is a different approach to exposing values/methods in the UStruct instead?
The main difference is in the construction/destruction process I think.
UCLASS objects have a fairly complicated initialization process and will always be allocated on the heap. They are also garbage collected.
USTRUCTS are essentially just C++ structs with support for member (but not method) reflection. They can be created just by declaring a regular variable. So when you have a lot of objects being created and destroyed, USTRUCT is far more lightweight.
I’m not clear on exactly what you’re trying to do. Presumably you’re looking at modifying the engine code? Changing FAIStimulus to a UCLASS would involve modifying a fair bit of supporting code. By the way, if you’re accessing the stimulus through FActorPerceptionBlueprintInfo, I’m pretty sure that the index in the array corresponds to the FAISenseID. Problem is, even if you get the sense ID, I’m not sure there’s anything you can do with it from blueprint currently anyway, is there?
I can think of one approach to access the IsActive method from blueprint (and it may work for what you’re trying to accomplish with the sense type, too) - create a blueprint function library with some helpers. Something like this:
What I’m after is exposing two more things from that struct. Basically right now, there’s no way to know if the sense is now not-sensed. So you get a list of senses but can’t tell which ones are sensed and which ones arent. Also, there’s no way to tell WHICH sense is being sensed from the struct as it is. Unless you’re right and the sense ID is the index, but that wouldn’t be safe to assume because different Perception Component settings might have different senses setup in their sense arrays.
Your solution of a blueprint function library might well be the answer there though. I never thought of that ;0 thanks for the suggestion!