Hey, I’m pretty new to Unreal and I’m trying to figure out how I might extend the UAISense_Sight class. Creating a derived class that overrides some functions is simple enough, and then I can change the sense implementation to my derived class, and that all works fine.
The bit I’m having trouble with is what if I also need to extend UAISenseConfig_Sight to add some new parameters that are necessary for this extended implementation? I can create a derived class of the sight config, but in the actual sense class that config is turned into an FDigestedSightProperties struct, which takes a UAISenseConfig_Sight specifically. So I could derive from FDigestedSightProperties and add these new parameters to that as well, and a constructor that takes my new config class.
This is where I seem to get stuck. UAISense_Sight stores those digested properties in a TMap<FPerceptionListenerID, FDigestedSightProperties> called DigestedProperties, which is used in various places to look up the properties for each listener. That I can’t override without making an alternate map in my derived class, and overriding all functions that use it so that it points to my new map, which would be silly, at that point I might as well just duplicate the entire class.
It kinda feels like I’m missing something, but maybe the intention is that you only create entirely new senses rather than trying to add to the existing ones? I could basically just copy UAISense_Sight and the config and make additions to those rather than deriving from it, but obviously that’s not ideal. Plus the ‘Implementation’ in the config being a TSubclassOf seems to imply that extending these classes is the intended way to go about this…
Not really. If you want a more specific example, say I wanted to split PeripheralVisionAngleDegrees into separate horizontal and vertical vision angles (Because real life horizontal field of view is much larger than vertical and it currently just does a dot product to check if an actor is within that angle in any direction), but keep the rest of the UAISense_Sight functionality.
If I want to do that I first need to change the config so that it has two separate angles in, instead of the one it currently has. But the map of digested properties structs that the UAISense_Sight class uses can’t be changed in a derived class, so I can’t see a way to do that.
Yes, that may be challenging. But you can always query PeripheralVisionAngleDegrees like I did above and then simply run your own custom checks afterwards as workaround.
AI Perception is kind of an abandonware so I feel like we’re all scraping the barrel with its capabilities.
edit: Also look into CanBeSeenFrom function. You can add your additional vertical vision angle logic in there on top of usual linetrace without overriding SightSense.