Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

ConstructorHelpers::FObjectFinder crashing in constructor

In my constructor I have this code:

 static ConstructorHelpers::FObjectFinder<USoundWave> objFinder(TEXT("SoundWave'/Game/UI/Sounds/Menu/MenuButtonClicked.MenuButtonClicked'"));

When it is executed ("Play" inside the editor) it crashes with:

 Fatal error: [File:D:\Build\++UE4+Release-4.17+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 3233] FObjectFinders can't be used outside of constructors to find SoundWave'/Game/UI/Sounds/Menu/MenuButtonClicked.MenuButtonClicked'

which is exactly the above line.

Any ideas? Perhaps I have to have certain macros in the class header or something like that?

Product Version: UE 4.17
more ▼

asked Oct 12 '17 at 07:34 PM in C++ Programming

avatar image

183 8 13 13

avatar image Greywacke Oct 12 '17 at 08:09 PM

I assume you got that string by right clicking the asset and selecting "Copy Reference"?

Try setting your path file string to this:

 static ConstructorHelpers::FObjectFinder<USoundWave> objFinder(TEXT("'/Game/UI/Sounds/Menu/MenuButtonClicked'"));

Hoping that does it!

avatar image BugSwat Oct 12 '17 at 08:31 PM

No, it was a good idea, I tried different variants

  • SoundWave'/Game/UI/Sounds/Menu/MenuButtonClicked.MenuButtonClicked'

  • SoundWave'/Game/UI/Sounds/Menu/MenuButtonClicked'

  • Game/UI/Sounds/Menu/MenuButtonClicked

I tried to get an UObject instead of a USoundWave, no change.

When I use

 UObject* objFinder = StaticLoadObject(USoundWave::StaticClass(), nullptr, TEXT("SoundWave'/Game/UI/Sounds/Menu/MenuButtonClicked.MenuButtonClicked'"));

it seems to work. At least

 USoundWave* pSoundClick = dynamic_cast <USoundWave*> (objFinder);

does not give me a nullptr.

Now I have to find out how to play a SoundWave or - better - how to convert a SoundWave to a FSlateSound to know if I really loaded that asset.

It would just be nice to be able to use the normally used method. Or at least to know why it crashes. Makes me think something is really wrong here with my code. :-(

avatar image Greywacke Oct 12 '17 at 08:48 PM

Just checked in my own project, and this is my code:

     static ConstructorHelpers::FObjectFinder<USoundBase> FireAudio(TEXT("/Game/TwinStick/Audio/KKIIDDZZ_00018"));
     FireSound = FireAudio.Object;

and in my .h file :

     UPROPERTY(Category = Audio, EditAnywhere, BlueprintReadWrite)
         class USoundBase* FireSound;

I'm not sure what the difference is between USoundBase and USoundWave, but that might be the problem? :P

avatar image BugSwat Oct 12 '17 at 09:01 PM

NOW I am really confused. I thought, if you do it your way, you can just use FireSound, no need for any ObjectFinder.

I want to avoid the URPOPERTY way here, if I have to, I will use it, but I'll try for a bit.

Did you ever try to just use the FireSound?

avatar image Greywacke Oct 12 '17 at 09:14 PM

I'm sorry, it was a fair while ago I set this up, so I just had to go and check where the sound was used. I currently have this code to play a 2D sound (though the commented out line should create a 3D sound effect ) using FireSound:

     if (FireSound != nullptr)
         UGameplayStatics::PlaySound2D(this, FireSound);    
         //UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation());

I'm quite sure that I need to either use an object finder (as I did) or assign the variable via blueprint in order for FireSound to make a sound.

You shouldn't require UPROPERTY() , though I'm not certain on that - UE4 can be funny about its macros sometimes!

Am I being clear enough? Cos I'm not certain that I am =P

Edit: Here's the include for UGameplayStatistics:

  #include "Kismet/GameplayStatics.h"

avatar image BugSwat Oct 12 '17 at 10:07 PM

Thank you. That should help with the tests.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question