{"id":4137,"date":"2024-03-30T02:00:29","date_gmt":"2024-03-29T18:00:29","guid":{"rendered":"https:\/\/lonelinerd.com\/?p=4137"},"modified":"2024-03-30T02:10:54","modified_gmt":"2024-03-29T18:10:54","slug":"ue5_ai_perception_event","status":"publish","type":"post","link":"https:\/\/lonelinerd.com\/index.php\/2024\/03\/30\/ue5_ai_perception_event\/","title":{"rendered":"[C++\/UE] UE5\u4e2dAI\u958b\u767c\u7684\u4e00\u9ede\u529f\u80fd\u68b3\u7406\uff08\u516d\uff09 \u2013 AI Perception \u611f\u77e5\u7cfb\u7d71 Event\u90e8\u5206"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"4137\" class=\"elementor elementor-4137\">\n\t\t\t\t\t\t<div class=\"elementor-inner\">\n\t\t\t\t<div class=\"elementor-section-wrap\">\n\t\t\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-ac45dc4 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"ac45dc4\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-73b82da\" data-id=\"73b82da\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-b41a558 elementor-widget elementor-widget-text-editor\" data-id=\"b41a558\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<h4><span style=\"text-decoration: underline;\"><strong>Events<\/strong><\/span><\/h4><ul><li>AI Perception\u53ef\u4ee5\u70ba\u6240\u9644\u7684AI Controller blueprint\u63d0\u4f9b\u4e00\u4e9b\u611f\u77e5\u66f4\u65b0\u6642\u89f8\u767c\u7684\u4e8b\u4ef6\uff0cAI Controller\u53ef\u5c31\u8457\u9019\u4e9b\u4e8b\u4ef6\u89f8\u767c\u7684\u6642\u6a5f\uff0c\u7de8\u5bebAI\u89d2\u8272\u5728\u611f\u77e5\u66f4\u65b0\u6642\u7684\u8655\u7406<\/li><\/ul>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-21e2e18 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"21e2e18\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-2ea0457\" data-id=\"2ea0457\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-1d14f0f elementor-widget elementor-widget-image\" data-id=\"1d14f0f\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-image\">\n\t\t\t\t\t\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"553\" height=\"262\" src=\"https:\/\/lonelinerd.com\/wp-content\/uploads\/2024\/03\/PerceptionUpdateEvent.png\" class=\"attachment-large size-large wp-image-4146\" alt=\"\" srcset=\"https:\/\/lonelinerd.com\/wp-content\/uploads\/2024\/03\/PerceptionUpdateEvent.png 553w, https:\/\/lonelinerd.com\/wp-content\/uploads\/2024\/03\/PerceptionUpdateEvent-300x142.png 300w\" sizes=\"auto, (max-width: 553px) 100vw, 553px\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-b7fa849 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"b7fa849\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b147e38\" data-id=\"b147e38\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-012a253 elementor-widget elementor-widget-text-editor\" data-id=\"012a253\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>OnPerceptionUpdated<\/strong>\n<ul>\n<li>\u53ea\u8981\u6709\u5c0d\u8c61\u66f4\u65b0\u611f\u77e5\u7cfb\u7d71\u5c31\u8abf\u7528\uff0c\u7121\u8ad6\u6709\u6c92\u6709\u7d81\u5b9a\u8a72\u51fd\u6578\u81f3\u85cd\u5716\u5167<\/li>\n<li>\u6bcf\u6b21\u8abf\u7528\u90fd\u628a\u6240\u6709\u5c0d\u8c61\u4f5c\u70ba\u53c3\u6578\u50b3\u5165\uff08Actor\u5217\u8868\uff09<\/li>\n<\/ul>\n<\/li>\n<li><strong>OnTargetPerceptionForgotten<\/strong>\n<ul>\n<li>\u5404\u611f\u77e5\u7cfb\u7d71\u53ef\u914d\u7f6eMaxLife\u6307\u5b9a\u5c0d\u8c61\u88ab\u611f\u77e5\u5230\u7684\u6301\u7e8c\u6642\u9593<\/li>\n<li>\u7576\u9019\u4e9b\u5c0d\u8c61\u88ab\u300c\u907a\u5fd8\u300d\u6642\uff0c\u89f8\u767c\u4e8b\u4ef6\u4e26\u50b3\u5165\u8a72\u5c0d\u8c61\u7684Actor<\/li>\n<\/ul>\n<\/li>\n<li><strong>OnTargetPerceptionUpdated<\/strong>\n<ul>\n<li>\u611f\u77e5\u7cfb\u7d71\u63a5\u6536\u5230\u66f4\u65b0\u4fe1\u865f\u6642\u89f8\u767c\uff0c\u50b3\u5165\u767c\u51fa\u66f4\u65b0\u4fe1\u865f\u7684\u67d0\u500b\u5c0d\u8c61Actor\u7684\u5f37\u5f15\u7528\u53ca\u611f\u77e5\u7d30\u7bc0\uff08Stimuli\uff09<\/li>\n<\/ul>\n<\/li>\n<li><strong>OnTargetPerceptionInfoUpdated<\/strong>\n<ul>\n<li>\u611f\u77e5\u7cfb\u7d71\u63a5\u6536\u5230\u66f4\u65b0\u4fe1\u865f\u6642\u89f8\u767c\uff0c\u50b3\u5165\u767c\u51fa\u66f4\u65b0\u4fe1\u865f\u7684UpdateInfo\uff0cUpdateInfo\u5305\u542b\u4e86\u4ee5\u4e0b3\u500b\u6771\u897f\n<ul>\n<li>\u5c0d\u8c61\u6307\u91dd\u7684Hash<\/li>\n<li>\u5c0d\u8c61\u7684\u5f31\u5f15\u7528<\/li>\n<li>\u611f\u77e5\u7d30\u7bc0\uff08Stimuli\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u6d41\u7a0b\n<ul>\n<li>AIPerceptionSystem\u6bcf\u5e40\u904d\u6b77\u5168\u90e8AIPerception\u7d44\u4ef6\u4e26\u57f7\u884cProcessStimuli()<\/li>\n<li>\u5177\u9ad4\u7684AIPerceptionComponent\u88e1\u7684ProcessStimuli()\u4e3b\u8981\u6703\u9032\u884c\u4ee5\u4e0b\u8ddf\u4e0a\u8ff0\u4e8b\u4ef6\u76f8\u95dc\u7684\u5de5\u4f5c\n<ul>\n<li>\u6aa2\u67e5OnTargetPerceptionUpdated\u4e8b\u4ef6\u6709\u6c92\u6709\u7d81\u5b9a<\/li>\n<li>\u6aa2\u67e5OnTargetPerceptionInfoUpdated\u4e8b\u4ef6\u6709\u6c92\u6709\u7d81\u5b9a<\/li>\n<li>\u904d\u6b77\u5168\u90e8\u611f\u77e5\u5217\u8868\uff0c\u5047\u8a2d\u6bcf\u500b\u5143\u7d20\u70bas\n<ul>\n<li>ProcessingStimuli -&gt; \u5404\u611f\u77e5\u9805\u6bcf\u5e40\u6aa2\u6e2c\uff0c\u5728\u611f\u77e5\u6709\u66f4\u65b0\u6642\uff0c\u6703\u5be6\u4f8b\u5316\u4e00\u500bStimuli\uff0c\u88e1\u9762\u5305\u542b\u5fc5\u8981\u4fe1\u606f\uff0c\u4e26\u5c07\u5b83\u52a0\u5230\u5217\u8868\u88e1\uff0c\u5982\u4e0b\u9762\u7684\u793a\u4f8b\uff08\u5f9eAISense_Damage\u958b\u59cb\uff09<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-f2e8d37 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"f2e8d37\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-233f8fa\" data-id=\"233f8fa\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-da7d9c1 elementor-widget elementor-widget-code-block-for-elementor\" data-id=\"da7d9c1\" data-element_type=\"widget\" data-widget_type=\"code-block-for-elementor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<pre class='line-numbers theme-okaidia' data-show-toolbar='yes'><code class='language-cpp'>\/\/AISense_Damage.cpp\r\nfloat UAISense_Damage::Update()\r\n{\r\n    AIPerception::FListenerMap&amp; ListenersMap = *GetListeners();\r\n\r\n    for (const FAIDamageEvent&amp; Event : RegisteredEvents)\r\n    {\r\n        IAIPerceptionListenerInterface* PerceptionListener = Event.GetDamagedActorAsPerceptionListener();\r\n        if (PerceptionListener != nullptr)\r\n        {\r\n            UAIPerceptionComponent* PerceptionComponent = PerceptionListener-&gt;GetPerceptionComponent();\r\n            if (PerceptionComponent != nullptr &amp;&amp; PerceptionComponent-&gt;GetListenerId().IsValid())\r\n            {\r\n                \/\/ this has to succeed, will assert a failure\r\n                FPerceptionListener&amp; Listener = ListenersMap[PerceptionComponent-&gt;GetListenerId()];\r\n\r\n                if (Listener.HasSense(GetSenseID()))\r\n                {\r\n                    Listener.RegisterStimulus(Event.Instigator, FAIStimulus(*this, Event.Amount, Event.Location, Event.HitLocation, FAIStimulus::SensingSucceeded, Event.Tag));\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    RegisteredEvents.Reset();\r\n\r\n    \/\/ return decides when next tick is going to happen\r\n    return SuspendNextUpdate;\r\n}\r\n\r\n\/\/AIPerceptionTypes.cpp\r\nvoid FPerceptionListener::RegisterStimulus(AActor* Source, const FAIStimulus&amp; Stimulus)\r\n{\r\n    bHasStimulusToProcess = true;\r\n    Listener-&gt;RegisterStimulus(Source, Stimulus);\r\n}\r\n\r\n\/\/AIPerceptionComponent.cpp\r\nvoid UAIPerceptionComponent::RegisterStimulus(AActor* Source, const FAIStimulus&amp; Stimulus)\r\n{\r\n    FStimulusToProcess&amp; StimulusToProcess = StimuliToProcess.Add_GetRef(FStimulusToProcess(Source, Stimulus));\r\n    StimulusToProcess.Stimulus.SetExpirationAge(MaxActiveAge[int32(Stimulus.Type)]);\r\n}<\/code><\/pre>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-fb7d424 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"fb7d424\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-dbc6084\" data-id=\"dbc6084\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a3be4ff elementor-widget elementor-widget-text-editor\" data-id=\"a3be4ff\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-text-editor elementor-clearfix\">\n\t\t\t\t<ul><li style=\"list-style-type: none;\"><ul><li>\u4e00\u4e9b\u53ef\u884c\u6027\u6aa2\u6e2c\uff0c\u78ba\u4fdd\u611f\u77e5\u6210\u529f\uff0c\u4e26\u5617\u8a66\u628a\u611f\u77e5\u5c0d\u8c61\u8f49\u6210Actor\uff0c\u5931\u6557\u76f4\u63a5continue<\/li><li>\u6839\u64da\u4e0a\u6b21\u8a72\u611f\u5b98\u611f\u77e5\u5230\u7684\u5c0d\u8c61\u8ddf\u7576\u524d\u611f\u77e5\u5230\u7684\u5c0d\u8c61\u4ee5\u53caWantsToNotifyOnlyOnValueChange\u914d\u7f6e\u9805\u4f86\u78ba\u5b9a\u6a19\u8a18\u4f4dbActorInfoUpdated\uff08ActorInfo\u4fe1\u606f\u662f\u5426\u6709\u8b8a\u52d5\uff09\uff0c\u4e0b\u7a31\u300c\u9700\u8981\u66f4\u65b0\u300d<\/li><li>\u6839\u64da\u5177\u9ad4\u7684\u611f\u77e5\u60c5\u6cc1\uff0c\u4f5c\u51fa\u4ee5\u4e0b\u5206\u652f\u8655\u7406<ul><li>\u5982\u679c\u67d0\u500b\u611f\u5b98\u611f\u77e5\u5230\u65b0\u5c0d\u8c61\uff0c\u4e14\u611f\u77e5\u66f4\u5f37\u6216\u66f4\u5e74\u8f15\uff0c\u5c31\u4f7f\u65b0\u5c0d\u8c61\u53d6\u4ee3\u8001\u5c0d\u8c61<\/li><li>\u5982\u679c\u6c92\u6709\u65b0\u5c0d\u8c61\u4e14\u8001\u5c0d\u8c61\u6c92\u6709\u300c\u904e\u671f\u300d\uff0c\u4e26\u9700\u8981\u66f4\u65b0\uff0c\u6a19\u8a18\u5c0d\u8c61\u4e0d\u9700\u8981\u518d\u88ab\u91cd\u65b0\u611f\u77e5\uff0cAge\u8a2d\u7f6e\u70ba0<\/li><li>\u8001\u5c0d\u8c61\u5df2\u904e\u671f\uff0c\u628a\u5c0d\u8c61\u52a0\u5230\u300c\u5f85\u907a\u5fd8Actor\u300d\u5217\u8868\u4e2d<\/li><\/ul><\/li><li>\u5982\u9700\u8981\u66f4\u65b0<ul><li>\u5982\u6709\u7d81\u5b9aOnTaregetPerceptionUpdated\u4e8b\u4ef6\uff0c\u5c31\u6703\u8abf\u7528OnTargetPerceptionUpdated\uff0c\u628a\u5c0d\u8c61\u7684\u5f37\u5f15\u7528\u548c\u611f\u77e5\u7684\u4fe1\u606f\u7d30\u7bc0\u5ee3\u64ad\u51fa\u53bb<\/li><li>\u5982\u6709\u7d81\u5b9aOnTargetPerceptionInfoUpdated\u4e8b\u4ef6\uff0c\u5c31\u6703\u8abf\u7528OnTargetPerceptionInfoUpdated\uff0c\u4e26\u5275\u5efa\u4e00\u500bUpdateInfo\u5c0d\u8c61\uff0c\u628a\u76f8\u95dc\u4fe1\u606f\u5ee3\u64ad\u51fa\u53bb\uff0cUpdateInfo\u5305\u542b\u4ee5\u4e0b\u8cc7\u8a0a<ul><li>TargetId\uff1a\u5c0d\u8c61\u6307\u91dd\u7684Hash<\/li><li>\u5c0d\u8c61\u7684\u5f31\u5f15\u7528<\/li><li>\u611f\u77e5\u4fe1\u606f\u7d30\u7bc0<\/li><\/ul><\/li><li>\u628a\u6240\u6709\u89f8\u767c\u611f\u77e5\u66f4\u65b0\u7684Actor\u90fd\u8d70OnPerceptionUpdated\u4e8b\u4ef6\u5ee3\u64ad\u51fa\u53bb<\/li><li>\u5982\u679c\u7d81\u4e86OnTargetPerceptionForgotten\u4e8b\u4ef6\uff0c\u5c31\u904d\u6b77\u300c\u5f85\u907a\u5fd8Actor\u300d\u5217\u8868\uff0c\u628a\u6bcf\u500bActor\u90fd\u8d70\u9019\u500b\u4e8b\u4ef6\u5ee3\u64ad\u51fa\u53bb\uff0c\u6bcf\u500bActor\u5ee3\u64ad\u4e00\u6b21<\/li><\/ul><\/li><\/ul><\/li><\/ul>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-22c1eb3 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"22c1eb3\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-5e28ebb\" data-id=\"5e28ebb\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e7f02d6 elementor-widget elementor-widget-code-block-for-elementor\" data-id=\"e7f02d6\" data-element_type=\"widget\" data-widget_type=\"code-block-for-elementor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<pre class='line-numbers theme-okaidia' data-show-toolbar='yes'><code class='language-cpp'>\/\/AIPerceptionSystem.cpp\r\nvoid UAIPerceptionSystem::Tick(float DeltaSeconds)\r\n{\r\n    \/\/...\r\n    if(ListenerIt-&gt;Value.HasAnyNewStimuli())\r\n    {\r\n        ListenerIt-&gt;Value.ProcessStimuli();\r\n    }\r\n    \/\/...\r\n}\r\n\r\n\/\/AIPerceptionTypes.cpp\r\nvoid FPerceptionListener::ProcessStimuli()\r\n{\r\n    ensure(bHasStimulusToProcess);\r\n    Listener-&gt;ProcessStimuli();\r\n    bHasStimulusToProcess = false;\r\n}\r\n\r\n\/\/AIPerceptionComponent\r\nvoid UAIPerceptionComponent::ProcessStimuli()\r\n{\r\n    SCOPE_CYCLE_COUNTER(STAT_AI_PercepComp_ProcessStimuli);\r\n    \r\n    if(StimuliToProcess.Num() == 0)\r\n    {\r\n        UE_VLOG(GetOwner(), LogAIPerception, Warning, TEXT(&quot;UAIPerceptionComponent::ProcessStimuli called without any Stimuli to process&quot;));\r\n        return;\r\n    }\r\n\r\n    const bool bBroadcastEveryTargetUpdate = OnTargetPerceptionUpdated.IsBound();\r\n    const bool bBroadcastEveryTargetInfoUpdate = OnTargetPerceptionInfoUpdated.IsBound();\r\n    \r\n    TArray&lt;FStimulusToProcess&gt; ProcessingStimuli = MoveTemp(StimuliToProcess);\r\n    TArray&lt;AActor*&gt; UpdatedActors;\r\n    UpdatedActors.Reserve(ProcessingStimuli.Num());\r\n    TArray&lt;AActor*&gt; ActorsToForget;\r\n    ActorsToForget.Reserve(ProcessingStimuli.Num());\r\n    TArray&lt;TObjectKey&lt;AActor&gt;, TInlineAllocator&lt;8&gt;&gt; DataToRemove;\r\n\r\n    for (FStimulusToProcess&amp; SourcedStimulus : ProcessingStimuli)\r\n    {\r\n        const TObjectKey&lt;AActor&gt;&amp; SourceKey = SourcedStimulus.Source;\r\n\r\n        FActorPerceptionInfo* PerceptualInfo = PerceptualData.Find(SourceKey);\r\n        AActor* SourceActor = nullptr;\r\n\r\n        if (PerceptualInfo == NULL)\r\n        {\r\n            if (SourcedStimulus.Stimulus.WasSuccessfullySensed() == false)\r\n            {\r\n                \/\/ this means it's a failed perception of an actor our owner is not aware of\r\n                \/\/ at all so there's no point in creating perceptual data for a failed stimulus\r\n                continue;\r\n            }\r\n            else\r\n            {\r\n                SourceActor = CastChecked&lt;AActor&gt;(SourceKey.ResolveObjectPtr(), ECastCheckedType::NullAllowed);\r\n\r\n                \/\/ no existing perceptual data and source no longer valid: nothing to do with this stimulus\r\n                if (SourceActor == nullptr)\r\n                {\r\n                    continue;\r\n                }\r\n                \r\n                \/\/ create an entry\r\n                PerceptualInfo = &amp;PerceptualData.Add(SourceKey, FActorPerceptionInfo(SourceActor));\r\n                \/\/ tell it what's our dominant sense\r\n                PerceptualInfo-&gt;DominantSense = DominantSenseID;\r\n\r\n                PerceptualInfo-&gt;bIsHostile = (FGenericTeamId::GetAttitude(GetOwner(), SourceActor) == ETeamAttitude::Hostile);\r\n            }\r\n        }\r\n\r\n        if (PerceptualInfo-&gt;LastSensedStimuli.Num() &lt;= SourcedStimulus.Stimulus.Type)\r\n        {\r\n            const int32 NumberToAdd = SourcedStimulus.Stimulus.Type - PerceptualInfo-&gt;LastSensedStimuli.Num() + 1;\r\n            PerceptualInfo-&gt;LastSensedStimuli.AddDefaulted(NumberToAdd);\r\n        }\r\n\r\n        check(SourcedStimulus.Stimulus.Type.IsValid());\r\n\r\n        FAIStimulus&amp; StimulusStore = PerceptualInfo-&gt;LastSensedStimuli[SourcedStimulus.Stimulus.Type];\r\n        const bool bActorInfoUpdated = SourcedStimulus.Stimulus.WantsToNotifyOnlyOnPerceptionChange() == false \r\n            || SourcedStimulus.Stimulus.WasSuccessfullySensed() != StimulusStore.WasSuccessfullySensed();\r\n\r\n        if (SourcedStimulus.Stimulus.WasSuccessfullySensed())\r\n        {\r\n            RefreshStimulus(StimulusStore, SourcedStimulus.Stimulus);\r\n        }\r\n        else if (StimulusStore.IsExpired() == false)\r\n        {    \r\n            if (bActorInfoUpdated)\r\n            {\r\n                \/\/ @note there some more valid info in SourcedStimulus-&gt;Stimulus regarding test that failed\r\n                \/\/ may be useful in future\r\n                StimulusStore.MarkNoLongerSensed();\r\n                StimulusStore.SetStimulusAge(0);\r\n            }\r\n        }\r\n        else\r\n        {\r\n            HandleExpiredStimulus(StimulusStore);\r\n\r\n            if (bForgetStaleActors &amp;&amp; !PerceptualInfo-&gt;HasAnyCurrentStimulus())\r\n            {\r\n                if (AActor* ActorToForget = PerceptualInfo-&gt;Target.Get())\r\n                {\r\n                    ActorsToForget.Add(ActorToForget);\r\n                }\r\n            }\r\n        }\r\n\r\n        \/\/ if the new stimulus is &quot;valid&quot; or it's info that &quot;no longer sensed&quot; and it used to be sensed successfully\r\n        if (bActorInfoUpdated)\r\n        {\r\n            \/\/ Source Actor is only resolved from SourceKey when required but might already have been resolved for new entry\r\n            SourceActor = (SourceActor == nullptr) ? CastChecked&lt;AActor&gt;(SourceKey.ResolveObjectPtr(), ECastCheckedType::NullAllowed) : SourceActor;\r\n            if (SourceActor == nullptr)\r\n            {\r\n                DataToRemove.Add(SourceKey);\r\n            }\r\n            else\r\n            {\r\n                UpdatedActors.AddUnique(SourceActor);\r\n                if (bBroadcastEveryTargetUpdate)\r\n                {\r\n                    OnTargetPerceptionUpdated.Broadcast(SourceActor, StimulusStore);\r\n                }\r\n            }\r\n\r\n            if (bBroadcastEveryTargetInfoUpdate)\r\n            {\r\n                OnTargetPerceptionInfoUpdated.Broadcast(FActorPerceptionUpdateInfo(GetTypeHash(SourceKey), PerceptualInfo-&gt;Target, StimulusStore));\r\n            }\r\n        }\r\n    }\r\n\r\n    if (UpdatedActors.Num() &gt; 0)\r\n    {\r\n        if (AIOwner != NULL)\r\n        {\r\n            AIOwner-&gt;ActorsPerceptionUpdated(UpdatedActors);\r\n        }\r\n\r\n        OnPerceptionUpdated.Broadcast(UpdatedActors);\r\n    }\r\n\r\n    \/\/ forget actors that are no longer perceived\r\n    for (AActor* ActorToForget : ActorsToForget)\r\n    {\r\n        ForgetActor(ActorToForget);\r\n    }\r\n\r\n    \/\/ notify anyone interested\r\n    if (OnTargetPerceptionForgotten.IsBound())\r\n    {\r\n        for (AActor* ActorToForget : ActorsToForget)\r\n        {\r\n            OnTargetPerceptionForgotten.Broadcast(ActorToForget);\r\n        }\r\n    }\r\n\r\n    \/\/ remove perceptual info related to stale actors\r\n    for (const TObjectKey&lt;AActor&gt;&amp; SourceKey : DataToRemove)\r\n    {\r\n        PerceptualData.Remove(SourceKey);\r\n    }\r\n}\r\n\r\n<\/code><\/pre>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-9881655 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"9881655\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t\t\t<div class=\"elementor-row\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a18eb9b\" data-id=\"a18eb9b\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-column-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a9bce50 elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"a9bce50\" data-element_type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u70baUE AI\u7cfb\u5217\u7684\u7b2c\u516d\u90e8\u5206\uff1aAI Perception\u611f\u77e5\u7cfb\u7d71\u7684Event\u90e8\u5206<\/p>\n","protected":false},"author":1,"featured_media":4068,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,17],"tags":[],"class_list":["post-4137","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-notes","category-devnotes"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/lonelinerd.com\/wp-content\/uploads\/2024\/03\/FeatureCover_Unreal5ArtificialIntelligence.png","_links":{"self":[{"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/posts\/4137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/comments?post=4137"}],"version-history":[{"count":4,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/posts\/4137\/revisions"}],"predecessor-version":[{"id":4150,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/posts\/4137\/revisions\/4150"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/media\/4068"}],"wp:attachment":[{"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/media?parent=4137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/categories?post=4137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lonelinerd.com\/index.php\/wp-json\/wp\/v2\/tags?post=4137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}