{"id":5377,"date":"2023-11-09T08:18:07","date_gmt":"2023-11-09T00:18:07","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=5377"},"modified":"2023-11-09T08:56:20","modified_gmt":"2023-11-09T00:56:20","slug":"ue-actor%e7%94%9f%e5%91%bd%e5%91%a8%e6%9c%9f","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=5377","title":{"rendered":"UE Actor\u751f\u547d\u5468\u671f"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"923\" height=\"1912\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/11\/ActorLifeCycle1.png\" alt=\"\" class=\"wp-image-5380\" srcset=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/11\/ActorLifeCycle1.png 923w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/11\/ActorLifeCycle1-247x512.png 247w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/11\/ActorLifeCycle1-768x1591.png 768w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/11\/ActorLifeCycle1-24x50.png 24w\" sizes=\"(max-width: 923px) 100vw, 923px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u4ece\u78c1\u76d8\u52a0\u8f7d<\/h2>\n\n\n\n<p><strong>\u6446\u6b7b\u5728\u5173\u5361\u4e2d\u7684Actor\uff0c\u5f53 UEngine::LoadMap \u53d1\u751f\u65f6\uff0c\u6216\u5f53\u5173\u5361\u6d41\u9001\u8c03\u7528 UWorld::AddToWorld \u65f6\u3002<\/strong><\/p>\n\n\n\n<ul><li>1.\u4ece\u78c1\u76d8\u52a0\u8f7d\u5305\/\u5173\u5361\u4e2d\u7684Actor\u3002<\/li><\/ul>\n\n\n\n<ul><li>2.\u5e8f\u5217\u5316\u7684Actor\u4ece\u78c1\u76d8\u52a0\u8f7d\u5b8c\u6210\u540e\u8c03\u7528 PostLoad \u3002\u6240\u6709\u81ea\u5b9a\u4e49\u7248\u672c\u5316\u548c\u4fee\u590d\u64cd\u4f5c\u5e94\u5728\u6b64\u5904\u6267\u884c\u3002PostLoad\u4e0e AActor::PostActorCreated \u4e92\u65a5\u3002<\/li><\/ul>\n\n\n\n<ul><li>3.\u4e16\u754c\u8c03\u7528 UAISystemBase::InitializeActorsForPlay \uff0c\u4ee5\u51c6\u5907Actor\u542f\u52a8Gameplay\u3002<\/li><\/ul>\n\n\n\n<ul><li>4.\u5173\u5361\u4e3a\u672a\u521d\u59cb\u5316\u7684Actor\u548c\u65e0\u7f1d\u884c\u7a0b\u7ed3\u8f6c\u8c03\u7528 ULevel::RouteActorInitialize \u3002<\/li><\/ul>\n\n\n\n<ul><li>5.\u5728Actor\u7684\u7ec4\u4ef6\u4e0a\u8c03\u7528InitializeComponent\u4e4b\u524d\u8c03\u7528 AActor::PreInitializeComponents \u3002<\/li><\/ul>\n\n\n\n<ul><li>6.UActorComponent::InitializeComponent \u662fActor\u4e0a\u5b9a\u4e49\u7684\u6bcf\u4e2a\u7ec4\u4ef6\u7684\u521b\u5efa\u8f85\u52a9\u51fd\u6570\u3002<\/li><\/ul>\n\n\n\n<ul><li>7.\u5728Actor\u7684\u7ec4\u4ef6\u521d\u59cb\u5316\u540e\uff0c\u8c03\u7528 AActor::PostInitializeComponents \u3002<\/li><\/ul>\n\n\n\n<ul><li>8.\u5173\u5361\u542f\u52a8\u540e\uff0c\u8c03\u7528 AActor::BeginPlay \u3002<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5728\u7f16\u8f91\u5668\u4e2d\u8fd0\u884c<\/h2>\n\n\n\n<p><strong>\u5728&#8221;\u5728\u7f16\u8f91\u5668\u4e2d\u8fd0\u884c\uff08Play in Editor\uff09&#8221;\u8def\u5f84\u4e2d\uff0cActor\u662f\u4ece\u7f16\u8f91\u5668\u4e2d\u590d\u5236\u800c\u6765\uff0c\u5e76\u975e\u4ece\u78c1\u76d8\u4e2d\u52a0\u8f7d\u3002\u7136\u540e\uff0c\u590d\u5236\u7684Actor\u6309\u4e0e&#8221;\u4ece\u78c1\u76d8\u52a0\u8f7d\uff08Load From Disk\uff09&#8221;\u8def\u5f84\u4e2d\u6240\u8ff0\u7684\u76f8\u540c\u6d41\u7a0b\u521d\u59cb\u5316\u3002<\/strong><\/p>\n\n\n\n<ul><li>\u5c06\u7f16\u8f91\u5668\u4e2d\u7684Actor\u590d\u5236\u5230\u65b0\u4e16\u754c\u4e2d\u3002<\/li><li>\u8c03\u7528 UObject::PostDuplicate \u3002<\/li><li>UAISystemBase::InitializeActorsForPlay<\/li><li>\u4e3a\u672a\u521d\u59cb\u5316\u7684Actor\u8c03\u7528 ULevel::RouteActorInitialize \uff0c\u6db5\u76d6\u65e0\u7f1d\u884c\u7a0b\u7ed3\u8f6c\u3002<\/li><li>\u5728Actor\u7684\u7ec4\u4ef6\u4e0a\u8c03\u7528InitializeComponent\u4e4b\u524d\u8c03\u7528 AActor::PreInitializeComponents \u3002<\/li><li>UActorComponent::InitializeComponent \u662fActor\u4e0a\u5b9a\u4e49\u7684\u6bcf\u4e2a\u7ec4\u4ef6\u7684\u521b\u5efa\u8f85\u52a9\u51fd\u6570\u3002<\/li><li>\u5728Actor\u7684\u7ec4\u4ef6\u521d\u59cb\u5316\u540e\uff0c\u8c03\u7528 AActor::PostInitializeComponents \u3002<\/li><li>\u5173\u5361\u542f\u52a8\u540e\uff0c\u8c03\u7528 AActor::BeginPlay \u3002<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u624b\u5de5\u521b\u5efa<\/h2>\n\n\n\n<ul><li>\u8c03\u7528 UWorld::SpawnActor \u3002<\/li><li>\u5728\u4e16\u754c\u4e2d\u751f\u6210Actor\u540e\uff0c\u8c03\u7528 AActor::PostSpawnInitialize \u3002<\/li><li>\u5df2\u751f\u6210Actor\u521b\u5efa\u540e\u4e3a\u5176\u8c03\u7528 AActor::PostActorCreated \uff0c\u6240\u6709\u6784\u9020\u51fd\u6570\u5b9e\u73b0\u884c\u4e3a\u5e94\u5728\u6b64\u53d1\u751f\u3002PostActorCreated\u4e0ePostLoad\u4e92\u65a5\u3002<\/li><li>AActor::ExecuteConstruction \uff1a<\/li><li>AActor::OnConstruction &#8211; Actor\u7684\u6784\u5efa\uff0c\u84dd\u56feActor\u7684\u7ec4\u4ef6\u5728\u6b64\u5904\u521b\u5efa\uff0c\u84dd\u56fe\u53d8\u91cf\u5728\u6b64\u5904\u521d\u59cb\u5316\u3002<\/li><li>AActor::PostActorConstruction \uff1a<ul><li>\u5728Actor\u7684\u7ec4\u4ef6\u4e0a\u8c03\u7528InitializeComponent\u4e4b\u524d\u8c03\u7528 AActor::PreInitializeComponents \u3002<\/li><li>UActorComponent::InitializeComponent \u662fActor\u4e0a\u5b9a\u4e49\u7684\u6bcf\u4e2a\u7ec4\u4ef6\u7684\u521b\u5efa\u8f85\u52a9\u51fd\u6570\u3002<\/li><li>\u5728Actor\u7684\u7ec4\u4ef6\u521d\u59cb\u5316\u540e\uff0c\u8c03\u7528 AActor::PostInitializeComponents \u3002<\/li><\/ul><\/li><li>UWorld::OnActorSpawned \u5728UWorld\u4e0a\u64ad\u653e\u3002<\/li><li>\u8c03\u7528 AActor::BeginPlay \u3002<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5ef6\u8fdf\u751f\u6210\">\u5ef6\u8fdf\u751f\u6210<\/h2>\n\n\n\n<p><strong>\u5c06\u4efb\u610f\u5c5e\u6027\u8bbe\u4e3a&#8221;\u751f\u6210\u65f6\u516c\u5f00\uff08Expose on Spawn\uff09&#8221;\u5373\u53ef\u5ef6\u8fdfActor\u751f\u6210\u3002<\/strong><\/p>\n\n\n\n<ol><li><a href=\"https:\/\/docs.unrealengine.com\/en-US\/API\/Runtime\/Engine\/Engine\/UWorld\/SpawnActorDeferred\"><strong>UWorld::SpawnActorDeferred<\/strong>&nbsp;<\/a>\u65e8\u5728\u751f\u6210\u6d41\u7a0b\u6027Actor\uff0c\u5141\u8bb8\u5728\u84dd\u56fe\u6784\u5efa\u811a\u672c\u4e4b\u524d\u8fdb\u884c\u989d\u5916\u8bbe\u7f6e\u3002<\/li><li>SpawnActor\u4e2d\u7684\u6240\u6709\u64cd\u4f5c\u53d1\u751f\uff0c\u4f46\u5728<a href=\"https:\/\/docs.unrealengine.com\/en-US\/API\/Runtime\/Engine\/GameFramework\/AActor\/PostActorCreated\">&nbsp;<strong>AActor::PostActorCreated<\/strong>&nbsp;<\/a>\u4e4b\u540e\u53d1\u751f\u4ee5\u4e0b\u64cd\u4f5c\uff1a<ol><li>\u901a\u8fc7\u4e00\u4e2a\u6709\u6548\u4f46\u4e0d\u5b8c\u6574\u7684Actor\u5b9e\u4f8b\u8bbe\u7f6e\u5e76\u8c03\u7528\u591a\u4e2a&#8221;\u521d\u59cb\u5316\u51fd\u6570&#8221;\u3002<\/li><li>\u8c03\u7528<a href=\"https:\/\/docs.unrealengine.com\/en-US\/API\/Runtime\/Engine\/GameFramework\/AActor\/FinishSpawning\">&nbsp;<strong>AActor::FinishSpawning<\/strong>&nbsp;<\/a>\u4ee5\u6700\u7ec8\u786e\u5b9aActor\uff0c\u5728Spawn Actor\u884c\u4e2d\u7684<a href=\"https:\/\/docs.unrealengine.com\/en-US\/API\/Runtime\/Engine\/GameFramework\/AActor\/ExecuteConstruction\">&nbsp;<strong>AActor::ExecuteConstruction<\/strong>&nbsp;<\/a>\u9009\u53d6\u3002<\/li><\/ol><\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"407\" height=\"347\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/11\/image-19.png\" alt=\"\" class=\"wp-image-5390\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u78c1\u76d8\u52a0\u8f7d \u6446\u6b7b\u5728\u5173\u5361\u4e2d\u7684Actor\uff0c\u5f53 UEngine::LoadMap \u53d1\u751f\u65f6\uff0c\u6216\u5f53\u5173\u5361\u6d41\u9001\u8c03\u7528 UWor [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5377"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5377"}],"version-history":[{"count":9,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5377\/revisions"}],"predecessor-version":[{"id":5391,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5377\/revisions\/5391"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}