158{
160
161 if (InEnemyCharacter == nullptr)
162 {
163 return nullptr;
164 }
165
166 USkeletalMeshComponent* SourceMesh = InEnemyCharacter->GetMesh();
167 if (SourceMesh == nullptr || SourceMesh->GetSkeletalMeshAsset() == nullptr)
168 {
169 return nullptr;
170 }
171
172 UWorld* World = InEnemyCharacter->GetWorld();
173 if (World == nullptr)
174 {
175 return nullptr;
176 }
177
178 AActor* ProxyActor = World->SpawnActor<AActor>(AActor::StaticClass(), SourceMesh->GetComponentTransform());
179 if (ProxyActor == nullptr)
180 {
181 return nullptr;
182 }
183
184#if WITH_EDITOR
185 ProxyActor->SetFolderPath(FName(TEXT("EffectProxy/EnemyDespawn")));
186#endif
187
188 USkeletalMeshComponent* ProxyMesh = NewObject<USkeletalMeshComponent>(ProxyActor, TEXT("EnemyDespawnCopyPoseMesh"));
189 if (ProxyMesh == nullptr)
190 {
191 ProxyActor->Destroy();
192 return nullptr;
193 }
194
195 ProxyActor->SetRootComponent(ProxyMesh);
196 ProxyActor->AddInstanceComponent(ProxyMesh);
197 ProxyMesh->RegisterComponent();
198 ProxyMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
199 ProxyMesh->SetReceivesDecals(false);
200 ProxyMesh->SetCastShadow(false);
201 ProxyMesh->bCastDynamicShadow = false;
202 ProxyMesh->SetSkeletalMesh(SourceMesh->GetSkeletalMeshAsset(), false);
203 ProxyMesh->SetWorldTransform(SourceMesh->GetComponentTransform());
204 ProxyMesh->AttachToComponent(SourceMesh, FAttachmentTransformRules::KeepWorldTransform);
205 ProxyMesh->SetAnimationMode(EAnimationMode::AnimationBlueprint);
206 ProxyMesh->SetAnimInstanceClass(UEnemyDespawnCopyPoseAnimInstance::StaticClass());
207 ProxyMesh->TickAnimation(0.0f, false);
208 ProxyMesh->RefreshBoneTransforms();
209 ProxyMesh->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
210 ProxyMesh->SetWorldTransform(SourceMesh->GetComponentTransform());
211 ProxyMesh->SetComponentTickEnabled(false);
212 ProxyMesh->SetVisibility(false, false);
213 ProxyMesh->SetHiddenInGame(true, false);
214
218 return ProxyMesh;
219}
TWeakObjectPtr< UWorld > ActiveCopyPoseProxyWorld
Definition EnemyDespawnDefinition.h:99