Actor spawning issue

Hello.

To solidify my knowledge after following toontank course, I’ve tried to work on a personal project (industrial robot environment).
Basically, I need to pick up spare parts with my robot, and place them on a mechanical assembly in my scene.
I need to spawn those spare parts which are based on a class called SparePart, but with different static mesh according to the part.
I’ve tried the function used in toon tank course, and made this function :

void ASpawner::SpawnPart(int PartIndex) 
{

    FVector SpawnLocation = GetActorLocation();
    FRotator SpawnRotation = GetActorRotation();

        // if(PartList[PartIndex])
        // {
            if (SparePartClass)
            {
               UE_LOG(LogTemp, Warning, TEXT("Class pointer valid"));
               ASparePart* TempSparePart = GetWorld()->SpawnActor<ASparePart>(SparePartClass, SpawnLocation, SpawnRotation);
            }
            UE_LOG(LogTemp, Warning, TEXT("Spawning working"));
        // }
    }

Eventually, I need to choose the part I spawn from a list, hence the commented PartList array.
My issue is, as soon as I enter the if statement, the window freezes. This is probably due to a null pointer, but I can’t figure out where the issue is, especially since my test is true…

In the .h file, I’ve declared :

   TSubclassOf<ASparePart> SparePartClass;

Any idea ??

Thank you

How long have you waited when it freezed? It could be an assertion failing which can cause a freeze as it will generate a stacktrace to log out.

@DanM, What does this mean exactly? What do you mean by assertion and stacktrace?

I’ve waited something like 3-5 min

Assertion:
Assertion (software development) - Wikipedia,
Asserts | Unreal Engine Documentation
Stacktrace: the call stack that lead up to that assertion failing- Stack trace - Wikipedia

Have you looked at the logs? Could you post the contents?

Thanks @DanM.
Where can I find the logs if the editor crashes?

Build and PIE logs are in Saved > Logs and crashes in Saved > Crashes > (hash) > ProjectName.log

@DanM, looks like I don’t get the world :

LoginId:375d871b4a576645bfa61babeb19f8d7
EpicAccountId:1bd19a233db44e6d95f28ed6695b4378

Assertion failed: this->GetWorld() == nullptr [File:E:\UE_4.26\MECATHERM\Source\MECATHERM\Spawner.cpp] [Line: 24] No world!

UE4Editor_Core
UE4Editor_Core
UE4Editor_MECATHERM_8812!ASpawner::BeginPlay() [E:\UE_4.26\MECATHERM\Source\MECATHERM\Spawner.cpp:24]
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll

How can I solve this?

That is curious… Where do you have this spawner? I’m a little confused how there’s an actor without a world, honestly.

Same for me @DanM .
I’ve made a blueprint from my class “Spawner”, and placed it in my scene.
Here you’ve got pictures of everything I’ve done. Do you know anyone else who could help?




This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms