DaedalicEntertainment / ue4-orders-abilities

Sample code of the talk "Hero AI: Gameplay Abilities Meet Behaviour Trees" at Unreal Fest Europe 2019.
https://www.daedalic.com
MIT License
192 stars 58 forks source link

TSoftObjectPtr bug related to the blackboard and storing the OrderType class #4

Open fpwong opened 4 years ago

fpwong commented 4 years ago

Hi, I've been trying out your system for a while now and just recently tried to package my game. When playing for a while I got a fatal error. After some debugging it seems like there is a bug when using TSoftObjectPtr (or in this case TSoftClassPtr) and the blackboard.

So when we issue an order we load the TSoftClassPtr order class into the blackboard as our OrderType. When I leave a unit to attack or run a behaviour after approximately 2 minutes, the order class will unload itself and become a nullptr in the blackboard.

This is fairly annoying as you would have to go back out of the blackboard and ask our pawn's OrderComponent to reload the TSoftClassPtr through the CurrentOrder variable.

I have raised an issue about this on answerhub but was curious if you all encounted this bug.

https://answers.unrealengine.com/questions/948088/soft-object-unloads-when-stored-in-the-blackboard.html

Korky commented 3 years ago

I've been basing my implementation on yours and I have the issue where the Orders are null, you use the orders in the PlayerController or from somewhere else?

fpwong commented 3 years ago

@Korky I fixed this specific issue with the TSoftClassPtr by... removing the TSoftClassPtrs. Not quite the best solution but for the size of game I'm making even loading all the orders at once won't be an issue. I believe my branch has this change already pushed? Can't really remember too well what I last pushed to that.

And yes the orders are intially called from the player controller but still make their way to the behavior tree where they are used as in the original design.

Korky commented 3 years ago

Ok so I think I solved it yeah changing to SubClassOf working for me

npruehs commented 3 years ago

We just went for SoftClassPtrs to avoid strange compile-time issues (TSubclassOf requires you to include the full header, instead of just forward-declare the respective type).

If you can use TSubclassOf, that's great.

If not, just make sure to check whether the SoftClassPtr is valid, and call Load if not. As you already mentioned, loading an order at run-time should not be an issue with respect to performance.

Korky commented 3 years ago

I found my own way at the end of the day ... Im using GamplayAbilities as Orders too but a ability component owned by the Player ... GameplayTags are soo useful and powerful, Ill probably change the selection to a Effect

Korky commented 3 years ago

@npruehs so, interesting thing i found a bout my issue i got your Orders to work with SoftClassPtr if I assign the BP orders through config file straight into a variable