Crash trying to get material reference (C++/BP)

I’m trying to create a Blueprint node that brings in a specific material.

Firstly, I’m not even sure the code is correct as I’m new to C++ and struggling with it a bit.

Secondly, trying to use the node is causing the editor to crash every time.

Here is the code:

WriteToFile.h

#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "Paths.h"
#include "WriteToFile.generated.h"

/**
 *
 */
UCLASS()
class UWriteToFile : public UBlueprintFunctionLibrary
{
    GENERATED_UCLASS_BODY()
    
public:
    UFUNCTION(BlueprintCallable, meta = (DisplayName = "Get Material"), Category = "File-IO")
    static UMaterial* GetMaterial();
};

WriteToFile.cpp

#include "FilePlayground.h"
#include "WriteToFile.h"

UMaterial* UWriteToFile::GetMaterial()
{    
    static ConstructorHelpers::FObjectFinder <UMaterial>Material(TEXT("Material'/Game/Movies/Video_Tex_Mat.Video_Tex_Mat'"));
    return Material.Object;
}

Simply by wiring this node to the Level Blueprint BeginPlay node, the editor crashes.

Here are the diagnostic logs from the crash:

Diagnostics.txt: link text

FilePlayground.log: link text

info.txt: link text

As I said, I’m not sure if the code I’ve written is just crazy and causing the crash, of if the code should be fine (to return a reference to a material I can use in Blueprint) and some kind of bug is causing the crash.

System Specs:

  • Macbook Pro 17" (Late 2011)
  • 2.6 GHz Intel Core i7
  • 16 GB 1333 MHz DDR3
  • Intel HD Graphics 3000 512 MB
  • Running OSX 10.11.2
  • UE 4.10.4

Using ConstructorHelpers::FObjectFinder is not allowed outside of a constructor.

If you look into the diagnostics file you can see the following lines:

FDebug::AssertFailed(char const*, char const*, int, wchar_t const*, …) ← Assert failed = crash

ConstructorHelpers::CheckIfIsInConstructor(wchar_t const*) ← Where the assert failed

You can see that the CheckIfIsInConstructor is followed by AssertFailed, the diagnostics file contains the call stack that caused the crash usually if you follow it from bottom to top you can identify where the crash happened.