Create Decal Component Editor Crash

hello
am using UE4.7 i have an actor class and i want to use a decal as a component in the component tab,
in blueprints i would just add decal component form the drop-down menu

31412-bp_decal.png

but when i try to create UDecalComponent in C++ i try the following in my AActor Class
.h

UPROPERTY(VisibleDefaultsOnly, Category = "Decal")
class UDecalComponent* ActiveDecal;

in the constructor in ,cpp

ActiveDecal->CreateDefaultSubobject<UDecalComponent>(TEXT("Active Decal"));

the code compile with no errors in VS2013
but the editor crash with the following error [link text][3]

how can i achieve the same result as shown in the first photo in C++.

#Solution = Use GameplayStatics Library!

Epic has provided all the required functions here in GameplayStatics!

Enjoy!

GameplayStatic.h

/** Spawns a decal at the given location and rotation, fire and forget. Does not replicate.
	 * @param DecalMaterial - decal's material
	 * @param DecalSize - size of decal
	 * @param Location - location to place the decal in world space
	 * @param Rotation - rotation to place the decal in world space	
	 * @param LifeSpan - destroy decal component after time runs out (0 = infinite)
	 */
	UFUNCTION(BlueprintCallable, Category="Rendering|Components|Decal", meta=(WorldContext="WorldContextObject", UnsafeDuringActorConstruction = "true"))
	static UDecalComponent* SpawnDecalAtLocation(UObject* WorldContextObject, class UMaterialInterface* DecalMaterial, FVector DecalSize, FVector Location, FRotator Rotation = FRotator(-90, 0, 0), float LifeSpan = 0);

	/** Spawns a decal attached to and following the specified component. Does not replicate.
	 * @param DecalMaterial - decal's material
	 * @param DecalSize - size of decal
	 * @param AttachComponent - Component to attach to.
	 * @param AttachPointName - Optional named point within the AttachComponent to spawn the emitter at
	 * @param Location - Depending on the value of Location Type this is either a relative offset from the attach component/point or an absolute world position that will be translated to a relative offset
	 * @param Rotation - Depending on the value of LocationType this is either a relative offset from the attach component/point or an absolute world rotation that will be translated to a realative offset
	 * @param LocationType - Specifies whether Location is a relative offset or an absolute world position
	 * @param LifeSpan - destroy decal component after time runs out (0 = infinite)
	 */
	UFUNCTION(BlueprintCallable, Category="Rendering|Components|Decal", meta=(UnsafeDuringActorConstruction = "true"))
	static UDecalComponent* SpawnDecalAttached(class UMaterialInterface* DecalMaterial, FVector DecalSize, class USceneComponent* AttachToComponent, FName AttachPointName = NAME_None, FVector Location = FVector(ForceInit), FRotator Rotation = FRotator::ZeroRotator, EAttachLocation::Type LocationType = EAttachLocation::KeepRelativeOffset, float LifeSpan = 0);

#C++ Code

Here’s the C++ Code inside of GameplayStatic.cpp for creating a decal component!

UDecalComponent* CreateDecalComponent(class UMaterialInterface* DecalMaterial, FVector DecalSize, UWorld* World, AActor* Actor, float LifeSpan)
{
	const FMatrix DecalInternalTransform = FRotationMatrix(FRotator(0.f, 90.0f, -90.0f));

	UDecalComponent* DecalComp = ConstructObject<UDecalComponent>(UDecalComponent::StaticClass(), (Actor ? Actor : (UObject*)GetTransientPackage()));
	DecalComp->DecalMaterial = DecalMaterial;
	DecalComp->RelativeScale3D = DecalInternalTransform.TransformVector(DecalSize);
	DecalComp->bAbsoluteScale = true;
	DecalComp->RegisterComponentWithWorld(World);

	if (LifeSpan > 0.f)
	{
		DecalComp->SetLifeSpan(LifeSpan);
	}

	return DecalComp;
}

Crash Solution ~ ObjectInitializer

Your crash is this

Fatal error: [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.7\Engine\Source\Runtime\CoreUObject\Private\UObject\Obj.cpp] [Line: 60] 
Using incorrect object initializer.

Change this

ActiveDecal->CreateDefaultSubobject<UDecalComponent>(TEXT("Active Decal"));

to this

ActiveDecal = CreateDefaultSubobject<UDecalComponent>(TEXT("Active Decal"));

Otherwise you are calling a function on a pointer that has not yet be initialized!

You can also use the ObjectInitializer instead of using your parameter-free constructor!

#.h

UCLASS()
class CELESTIALCLEAVE_API ACCTTile : public AActor
{
    	GENERATED_BODY()
    public:
    	ACCTTile(const FObjectInitializer& ObjectInitializer);

#.cpp

ACCTTile::ACCTTile(const FObjectInitializer& ObjectInitializer) 
   : Super(ObjectInitializer)
{
        ActiveDecal = ObjectInitializer.CreateDefaultSubobject<UDecalComponent>(this, TEXT("Active Decal"));
	ActiveDecal->AttachParent = RootComponent;