x

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"

Why can't i dynamically load an animation BP in a packaged game ?

Hello !

I can't dynamically load an animation blueprint in a packaged game.

Here is my code (i tried both LoadObject and StaticLoadObject with the same result):

 FString AnimBPStringTest = "AnimBlueprint'/Game/mixamo/Heidi/IcloneAnimBP.IcloneAnimBP'";
 AnimationBP = Cast<UAnimBlueprint>(StaticLoadObject(UAnimBlueprint::StaticClass(), NULL, *AnimBPStringTest));

  • the directory containing the BP is cooked (added in the packaging option list)

  • this code works in editor but not in packaged game

  • the same code works well on a skeletal mesh (even in packaged game)

  • i get this error in the (packaged) logs:

    LogUObjectGlobals:Warning: Failed to find object 'AnimBlueprint /Game/mixamo/Heidi/IcloneAnimBP.IcloneAnimBP'

  • i have tried to package without the pak option and i can see the asset file in the package:

alt text

So the BP is cooked, the file is there, but it can't be loaded in packaged game, while a skeletal mesh in the same directory is correctly loaded.

Is there something special with animation blueprint as a packaged object ?

Sorry if this is no bug but i checked everything i could and can't see a reason for it not to load, considering it has been cooked and the code works in PIE.

Thanks !

Cedric

Product Version: UE 4.8
Tags:
more ▼

asked Jul 26 '15 at 06:38 PM in Bug Reports

avatar image

uced
850 75 89 360

avatar image Samantha Sutton ♦♦ STAFF Jul 27 '15 at 05:34 PM

Hey UCED,

Are you working within 4.8.2? If so, are did you obtain the engine from the Epic Games Launcher or through GitHub? Are you able to reproduce this in any project/template or a specific one? Are all dynamically loaded animation blueprints causing this problem? Please provide the exact reproduction steps in order to verify this bug within the engine.

Looking forward to hearing back from you, thanks!

avatar image uced Jul 27 '15 at 06:20 PM

Hey Samantha,

I am using 4.8.2 from the launcher (i don't use github).

Here are the repro steps that work on my computer:

  • create a 3rd person c++ project (i called it ReproAnimBP)

  • modify the code like this: in ReproAnimBP.h, replace #include "EngineMinimal.h" by #include "Engine.h" (just so we can use GEngine to print some message on screen)

  • in ReproAnimBPCharacter.h, declare the following:

    virtual void PostInitializeComponents() override;

  • In ReproAnimBPCharacter.cpp, add the following:

    void AReproAnimBPCharacter::PostInitializeComponents() { Super::PostInitializeComponents();

        FString AnimBPStringTest = "AnimBlueprint'/Game/ThirdPerson/Animations/ThirdPerson_AnimBP.ThirdPerson_AnimBP'";
         //AnimationBP = Cast<UAnimBlueprint>(StaticLoadObject(UAnimBlueprint::StaticClass(), NULL, *AnimBPStringTest));
         UAnimBlueprint* AnimationBP = LoadObject<UAnimBlueprint>(NULL, *AnimBPStringTest);
         if (!AnimationBP) return;
         GEngine->AddOnScreenDebugMessage(-1, 50.f, FColor::Green, "anim BP OK");
     }
    
    

Compile. You can then launch the game from the editor and you will see the message "Anim BP OK" on the screen.

Now, in the packaging options, leave only windows (not sure it's necessary though). I am using windows 8.1 up to date.

Then package the game and launch the packaged game.

The message is not displayed, and instead in the log, you'll find this:

 [2015.07.27-18.08.03:932][  0]LogUObjectGlobals:Warning: Failed to find object 'AnimBlueprint /Game/ThirdPerson/Animations/ThirdPerson_AnimBP.ThirdPerson_AnimBP'

Please let me know if you need any other info.

Cheers

Cedric

(comments are locked)
10|2000 characters needed characters left

4 answers: sort voted first

All right,

Just in case anyone bumps into this problem, here is some working code to dynamically load animation blueprint.

The trick is simple: never ever use blueprint, instead, use the class Luke.

 // get the blueprint class reference from the editor
 FString AnimClassStringTest = "Class'/Game/mixamo/Heidi/IcloneAnimBP.IcloneAnimBP_C'";
 
 // load the class
 UClass* AnimationClass = LoadObject<UClass>(NULL, *AnimClassStringTest);
 if (!AnimationClass) return;
 
 // assign the anim blueprint class to your skeletal mesh component
 Skeletal3DMeshComponent->SetAnimInstanceClass(AnimationClass);

And this is it :-)

Now if you want to drive your animation state through variables, here is the bonus.

Code a class inheriting from UAnimInstance to store all your BP variables (here i created the UYagCharacterAnimInstance class that contains the AnimTest integer).

Your animBP (here IcloneAnimBP) should be created in the editor inheriting from your own anim instance class (here UYagCharacterAnimInstance) instead of UAnimInstance

Then:

 // Assign the skeletal mesh component instance to your own instance
 UYagCharacterAnimInstance* AnimationBPInstance = Cast<UYagCharacterAnimInstance>(Skeletal3DMeshComponent->GetAnimInstance());
 if (!AnimationBPInstance) return;
 
 // You can now modify your variable (provided your anim BP, inheriting from your own anim instance class, knows how to handle this variable)
 AnimationBPInstance->AnimTest = 42;
 // This value will be passed to your anim BP and can drive some state modification, etc.

As always, it might not be the best way to do this but it works.

All this is done in the PostInitializeComponents function in my code but can be put anywhere else, the point is it's not in the constructor and is entirely dynamic.

I hope this helps !

Cheers

Cedric

more ▼

answered Aug 01 '15 at 08:43 AM

avatar image

uced
850 75 89 360

avatar image Bertram.Sch Dec 17 '15 at 12:06 PM

Thank you Cedric,

If anyone wants to change the AnimBP-Class on runtime, outside of constructors. This is the way to go. (UE 4.9)

(comments are locked)
10|2000 characters needed characters left

Hi,

In a packaged (or 'cooked') game, dynamic loading of non-cooked content is not supported. For content to be referenced by code you would need to use the FObjectFinder in your classes constructor instead of a plain old LoadObject(). For example:

 AReproAnimBPCharacter::AReproAnimBPCharacter(const FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer)
 {
     static ConstructorHelpers::FObjectFinder<UAnimBlueprint> AnimationBPFinder(TEXT("AnimBlueprint'/Game/ThirdPerson/Animations/ThirdPerson_AnimBP.ThirdPerson_AnimBP'"));
     AnimationBP = AnimationBPFinder.Object;
 }

This will ensure that the packaging process picks up the fact that the game needs to reference this asset.

See here for documentation on this.

more ▼

answered Jul 28 '15 at 09:11 AM

avatar image

Tom Sarkanen STAFF
1.7k 39 12 53

avatar image uced Jul 28 '15 at 09:38 AM

Hi Tom,

Thanks for you answer but (if i understand correctly) this is precisely what i do not want to do :-)

My concern is that i will have a lot of objects to load and i want to manage them from the windows directories/editor and not from the code, that's why i want to keep the constructor as free as possible from any reference to those objects and use dynamic loading.

I might have tens of such objects and don't want to change my code/recompile each time i add a new one. Of course, in the final version, the path will be a variable constructed at runtime from the directory structure. In the future, those objects might even be some optional content to be added later on, so everything should be manageable without touching the code. At least that's my goal.

In a dream world, i prepare the assets and the code knows where to search them, list them and loads them dynamically.

This seems to work well for all objects but not for anim blueprints, hence this ticket.

Also, in my main project (initial post), i specifically declared the directory to be cooked in the packaging options and double checked the presence of the asset file in the package. Does that not ensure that all objects in the directory are cooked and ready for the packaged game ?

Of course i am no expert and could have misunderstood something, i stay open to suggestions :-)

One thing i did not study yet is the whole ObjectLibrary thing, which i definitely should have a serious look at.

Thanks

Cedric

avatar image Tom Sarkanen STAFF Jul 28 '15 at 06:20 PM

If other assets are being correctly cooked (and therefore loaded) then it does indeed sound like something specific to AnimBPs. I'll log an issue to investigate this! Thanks for all the info!

(comments are locked)
10|2000 characters needed characters left

Hey Cedric,

Thank you so much for noticing this issue with the Unreal Engine. I have verified and reported this bug to our Developers. The Jira report is referenced as: UE-19239. If you happen to have any further questions or concerns, please feel free to reply back and I will assist you further.

Have a great day!

more ▼

answered Jul 27 '15 at 08:23 PM

(comments are locked)
10|2000 characters needed characters left

Hi,

After some more investigation, this is because UBlueprints (and derived classes, like UAnimBlueprints) are not loaded outside the editor. They are deemed to be editor-only constructs and their generated classes should be used in cooked games rather than the UBlueprint itself.

For reference, loading is controlled by UBlueprint::NeedsLoadForClient() and UBlueprint::NeedsLoadForServer().

See this question for more details.

more ▼

answered Jul 29 '15 at 09:33 AM

avatar image

Tom Sarkanen STAFF
1.7k 39 12 53

avatar image uced Jul 29 '15 at 12:57 PM

Hi Tom,

Funny, the question you point is a question i posted, i didn't make the connection :-)

I might try to play again with bDontLoadBlueprintOutsideEditor just for the fun of trying, but i don't feel confident enough to leave the main road for long.

Ok, thanks for the info, no good news for me, but oh well.

At least i now know for sure that i shouldn't try to make it work this way. I'm gonna try my luck with the object libraries, otherwise i'll rethink some other strategy.

Thanks for your time and the info, you guys are doing a great job with ue4 !

Cheers

Cedric

(comments are locked)
10|2000 characters needed characters left
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