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"

Using ConstructorHelpers::FObjectFinder within a for loop

I've been trying to reference multiple classes inside my actor by doing this:

 for(FString reference : weaponReferences){
     static ConstructorHelpers::FObjectFinder<UBlueprint> WeaponBlueprint(*reference);
     if (WeaponBlueprint.Succeeded()){

with 'weaponReferences' being a

 TArray<FString> weaponReferences;

in which I stored all blueprint locations and 'WeaponSpawn' being a

 TArray<TSubclassOf<class AWeapon>> WeaponSpawn;

However when I get the first and second object of 'WeaponSpawn' I get the exact same object although the paths are definitely different. Is there a way to clear the 'WeaponBlueprint' after I stored it in my Array? would that even help addressing the issue?

Excuse my weird formatting, I'm still trying to get used to the Text-Editor.

Product Version: UE 4.18
more ▼

asked Mar 03 '18 at 07:50 PM in C++ Programming

avatar image

3 1 4

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

1 answer: sort voted first


It happens, because you declared and initialized FObjectFinder as local static variable.

In such case, the variable is initialized only first time and persists through lifetime of the game and can be accessed in that scope as many times as you want.

Normally, doing that with FObjectFinder in constructor is a valid aproach. That way you don't have to actually search for given asset every time a constructor is called. In your case however it clearly won't work properly. To solve this, you could simply remove the 'static' keyword. BUT, that will have impact on performance (on constructing instances of your class). I don't know how big that impact would be tho.

If I were you, I'd consider removing that from constructor and keeping it as configurable, blueprint array.

Alternatively, you could refine your loop, so it would contain static map of that FObjectFinder and cache assets that you already found there. And then, instead of searching for assets everytime, you'd first check if these are already cached etc.


more ▼

answered Mar 04 '18 at 11:30 AM

avatar image

1.2k 18 23 40

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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