Announcement

Collapse
No announcement yet.

Calling CreateDefaultSubobject crashes editor!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    LOL, for me, this was using an unitialized pointer like this:

    ```
    OverlapComp->CreateDefaultSubobject<UBoxComponent>(TEXT("OverlapComp"));
    ```

    When I really meant to create an object like this:

    ```
    OverlapComp = CreateDefaultSubobject<UBoxComponent>(TEXT("OverlapComp"));
    ```

    Leave a comment:


  • replied
    Hey there, I have similar issue.

    I have an MyActor class derived from AActor class. I want to attach capsule component to MyActor object in runtime, so that I write following code

    Code:
        FVector NewLocation = FVector(0.f, 0.f, 0.f);
        MyActor* NewActor = GetWorld()->SpawnActor<MyActor>(ARTSActor::StaticClass(), NewLocation, FRotator::ZeroRotator);
        UCapsuleComponent* CapsuleCollider = CreateDefaultSubobject<UCapsuleComponent>(FName("Capsule"));
        CapsuleCollider->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);
    Whenever CreateDefaultSubobject function called editor crashes with following error.

    Code:
    Fatal error: [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/CoreUObject/Private/UObject/Obj.cpp] [Line: 107] No object initializer found during construction.
    If I move CreateDefaultSubobject and AttachToComponent functions to constructor of MyActor class, It works fine. Is there anyone know, why is this happening?

    Leave a comment:


  • replied
    Hang on, it turns out that the CreateDefaultSubobject was just commented out

    It's still broken D:

    I now have a mesh component in my parent class, so it isn't really a problem, but it would be nice to know why this is happening...
    Last edited by TheSporech; 09-20-2016, 04:37 PM.

    Leave a comment:


  • replied
    No problem

    Leave a comment:


  • replied
    Compile complete! Thank you!

    Leave a comment:


  • replied
    Try removing the class specifier " class USkeletalMeshComponent* GenMesh;"

    Leave a comment:


  • replied
    Can you see anything?

    Leave a comment:


  • replied
    Yes, it inherits from AActor. I can paste that class if it will help...
    Source:
    Code:
    // Fill out your copyright notice in the Description page of Project Settings.
    
    #include "RSGame.h"
    #include "InteractiveObject.h"
    #include <typeinfo>
    
    
    // Sets default values
    AInteractiveObject::AInteractiveObject()
    {
     	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    	PrimaryActorTick.bCanEverTick = true;
    
    	meshcomp = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Skeletal Mesh"));
    	meshcomp->CastShadow = true;
    	RootComponent = meshcomp;
    
    	hitbox = CreateDefaultSubobject<UBoxComponent>(TEXT("Hitbox"));
    	hitbox->OnComponentBeginOverlap.AddDynamic(this, &AInteractiveObject::BeginOverlap);
    
    	hitbox->SetRelativeLocation(FVector::ZeroVector);
    }
    
    // Called when the game starts or when spawned
    void AInteractiveObject::BeginPlay()
    {
    	Super::BeginPlay();
    
    	hitbox->SetRelativeLocation(FVector::ZeroVector);
    
    	epressed = false;
    	withinrange = false;
    }
    
    // Called every frame
    void AInteractiveObject::Tick( float DeltaTime )
    {
    	Super::Tick( DeltaTime );
    	if (nightguard->IsValidLowLevel())
    	{
    		epressed = nightguard->InteractingCPP;
    	}
    	if (withinrange && epressed)
    	{
    		OnInteract();
    	}
    }
    
    void AInteractiveObject::OnInteract()
    {
    	
    }
    
    void AInteractiveObject::BeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
    {
    	//if (typeid(OtherActor) == typeid(nightguard))
    	//{
    		nightguard = (ARSGameCharacter*) OtherActor;
    		withinrange = true;
    	//}
    }
    void AInteractiveObject::EndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
    {
    	//if (typeid(OtherActor) == typeid(nightguard))
    	//{
    		withinrange = false;
    	//}
    }
    (I know EndOverlap wouldn't work)

    Header:
    Code:
    // Fill out your copyright notice in the Description page of Project Settings.
    
    #pragma once
    
    #include "GameFramework/Actor.h"
    #include "RSGameCharacter.h"
    #include "InteractiveObject.generated.h"
    
    UCLASS()
    class RSGAME_API AInteractiveObject : public AActor
    {
    	GENERATED_BODY()
    
    	ARSGameCharacter* nightguard;
    
    public:	
    	// Sets default values for this actor's properties
    	AInteractiveObject();
    
    	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Collision")
    	UBoxComponent* hitbox;
    
    	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Mesh)
    	USkeletalMeshComponent* meshcomp;
    
    	// Called when the game starts or when spawned
    	virtual void BeginPlay() override;
    	
    	// Called every frame
    	virtual void Tick( float DeltaSeconds ) override;
    
    	virtual void OnInteract();
    
    	UFUNCTION()
    	void BeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResultr);
    	
    	UFUNCTION()
    	void EndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResultr);
    
    	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Interactivity")
    	bool withinrange;
    
    	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Interactivity")
    	bool epressed;
    	
    };

    Leave a comment:


  • replied
    Using incorrect object initializer
    Does AInteractiveObject inherit from AActor, or is it a plain UObject?

    Leave a comment:


  • replied
    Here's the dump...
    <EngineMode>Editor</EngineMode>
    <DeploymentName></DeploymentName>
    <EngineVersion>4.12.4-3028348+++UE4+Release-4.12</EngineVersion>
    <CommandLine> </CommandLine>
    <LanguageLCID>2057</LanguageLCID>
    <AppDefaultLocale>en_GB</AppDefaultLocale>
    <IsUE4Release>1</IsUE4Release>
    <UserName></UserName>
    <BaseDir>C:/Program Files (x86)/Epic Games/4.12/Engine/Binaries/Win64/</BaseDir>
    <RootDir>C:/Program Files (x86)/Epic Games/4.12/</RootDir>
    <MachineId>51D92D7C4808BB1B3E1BBF846D7D1DA5</MachineId>
    <EpicAccountId>1352a602544d4a9993ebd2c1f50f9535</EpicAccountId>
    <CallStack></CallStack>
    <SourceContext></SourceContext>
    <UserDescription></UserDescription>
    <UserActivityHint></UserActivityHint>
    <ErrorMessage>Fatal error: [File:\Build\++UE4+Release-4.12+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Obj.cpp] [Line: 85] &nl;Using incorrect object initializer.&nl;</ErrorMessage>
    <CrashDumpMode>0</CrashDumpMode>
    <CrashReporterMessage></CrashReporterMessage>
    <Misc.NumberOfCores>4</Misc.NumberOfCores>
    <Misc.NumberOfCoresIncludingHyperthreads>4</Misc.NumberOfCoresIncludingHyperthreads>
    <Misc.Is64bitOperatingSystem>1</Misc.Is64bitOperatingSystem>
    <Misc.CPUVendor>GenuineIntel</Misc.CPUVendor>
    <Misc.CPUBrand>Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz</Misc.CPUBrand>
    <Misc.PrimaryGPUBrand>NVIDIA GeForce GTX 970</Misc.PrimaryGPUBrand>
    <Misc.OSVersionMajor>Windows 10</Misc.OSVersionMajor>
    <Misc.OSVersionMinor></Misc.OSVersionMinor>
    <MemoryStats.TotalPhysical>17091260416</MemoryStats.TotalPhysical>
    <MemoryStats.TotalVirtual>140737488224256</MemoryStats.TotalVirtual>
    <MemoryStats.PageSize>65536</MemoryStats.PageSize>
    <MemoryStats.TotalPhysicalGB>16</MemoryStats.TotalPhysicalGB>
    <MemoryStats.AvailablePhysical>11671470080</MemoryStats.AvailablePhysical>
    <MemoryStats.AvailableVirtual>140736242065408</MemoryStats.AvailableVirtual>
    <MemoryStats.UsedPhysical>652484608</MemoryStats.UsedPhysical>
    <MemoryStats.PeakUsedPhysical>652484608</MemoryStats.PeakUsedPhysical>
    <MemoryStats.UsedVirtual>682799104</MemoryStats.UsedVirtual>
    <MemoryStats.PeakUsedVirtual>682799104</MemoryStats.PeakUsedVirtual>
    <MemoryStats.bIsOOM>0</MemoryStats.bIsOOM>
    <MemoryStats.OOMAllocationSize>0</MemoryStats.OOMAllocationSize>
    <MemoryStats.OOMAllocationAlignment>0</MemoryStats.OOMAllocationAlignment>
    </RuntimeProperties>
    <PlatformProperties>
    <PlatformIsRunningWindows>1</PlatformIsRunningWindows>
    <BuildIntegrityStatus>0</BuildIntegrityStatus>
    </PlatformProperties>
    </FGenericCrashContext>
    Attached Files
    Last edited by TheSporech; 09-19-2016, 04:07 PM.

    Leave a comment:


  • replied
    So, what does the call stack and output log say after the crash?

    Leave a comment:


  • replied
    Nope, it is defintely caused by that one line

    Leave a comment:


  • replied
    try commenting out the line? if its still crashing after that, the problem likely lies elsewhere
    Last edited by Chris528; 09-18-2016, 07:01 PM.

    Leave a comment:


  • replied
    No difference, the editor still crashes

    Leave a comment:


  • replied
    try this
    Code:
    GenMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("GenMesh"));

    Leave a comment:

Working...
X