Mori.Tako
(Mori.Tako)
June 20, 2022, 10:50am
1
I would like to clone a LevelInstance which holds the bunch of models.
For instance , my outliner shows the list of LevelInstance files which are loaded on the current level. And I would like to clone the “BPP_CHA_Ref_Level01_N1”(PackLevelActor) to the World.
FActorSpawnParameters param;
param.Template = mPackedLevel;
GetWorld()->SpawnActor<AActor>(AActor::StaticClass(), FTransform3d(mRot, mPos, mScale), param);
This didn’t work…
Warning: SpawnActor failed because template class (BPP_CHA_Ref_N1_C) does not match spawn class (Actor)
I tried in another way.
FActorSpawnParameters param;
TArray< UActorComponent* > components;
mPackedLevel->GetPackedComponents(components);
AActor* actor = GetWorld()->SpawnActor<AActor>(AActor::StaticClass(), FTransform3d(mRot, mPos, mScale), param);
for (auto& c : components) {
actor->AddComponentByClass(c->StaticClass(), true, FTransform3d(mRot, mPos, FVector(mScale)), true);
}
I’ve got a system-fault…
I really want to duplicate the models and place them.
Whoever know the answer-code, please show me.
Thanks in advance.
1 Like
I don’t know if it’s gonna work, but the error message should be an easy fix :
param.Template = mPackedLevel;
GetWorld()->SpawnActor<AActor>(mPackedLevel->GetClass(), FTransform3d(mRot, mPos, mScale), param);
Mori.Tako
(Mori.Tako)
June 27, 2022, 3:40am
3
Hello!
I tried your code, but still I got same warning, and the LevelInstance wasn’t cloned.
LogSpawn: Warning: SpawnActor failed because template class (BPP_CHA_Ref_Level01_N1_C) does not match spawn class (PackedLevelActor)
Anyway, thanks for reply. I’m appreciate with you kindness.
So sorry for late reply!! I couldn’t upload my reply, because of server error 500 from UE site.
Mori.Tako
(Mori.Tako)
June 28, 2022, 5:54am
4
I’m ashamed , I’ve mis-typed your code…
Your code works alright!!
The error has been gone. Thank’s a lot!!!
But, new warning comes out.
LogLevel: Warning: Failed to find streaming level object associated with ‘None’
Thit might be a new issue which I have to confront with.
It seems to be StreamingLevel problem.
Thank you!
Mori.Tako
(Mori.Tako)
June 29, 2022, 6:10am
5
My final answer for cloning the LevelInstance.
UWorld* data = LoadObject<UWorld>(nullptr, TEXT("/Game/ path for LevelInstance "), nullptr, LOAD_None, nullptr);
ALevelInstance* inst = GetWorld()->SpawnActor<ALevelInstance>(ALevelInstance::StaticClass(), FVector(100,0,0), FRotator(0,0,0));
inst->SetWorldAsset(data);
inst->LoadLevelInstance();
You can cache the UWorld-data into some variables.
static TMap<ID,UWorld*> gCache ;
like this. ID could be hashcode of filename.
So, only you have to do is…
Spawn the ALevelInstance at certain place
Set the asset-data by SetWorldAsset()
Call LoadLevelInstance()