I’m currently testing some stuff based on the Lyra sample game. In the animation blueprint (ABP_Mannequin_Base), there are repeated examples of Blueprint Thread Safe update functions to set values needed by the animation blueprint without accessing the game thread directly. They use the Property Access System, which I kind of understand.
However…Is there any way to access a property that requires a cast?
For example, I need to get some ragdoll info from my character blueprint. I’m actually using a system from the Metahuman example project, so there is a PhysicalBehaviorActorComponent in my character blueprint, which has a variable IsRagdolling. But I have no idea how to access that using the Property Access System. Is it possible?
Normally I could use TryGetPawnOwner, cast that to my character BP type, and call .PhysicalBehaviorActorComponent.GetIsRagdolling. But I can’t find a way to do the cast using the property access system.
Any help would be greatly appreciated. The only thing I can think of is using a custom engine build that adds a GetPhysicalBehaviorComponent function implemented the same way as the current GetMovementComponent() function on the base Pawn class, but that seems horribly complicated for what I want to do.
Basically, How do I do THIS:
Using the Property Access System?
So, I think I actually finally found the answer to this. I’m still doing some testing, but it looks like the answer is actually in the Lyra sample as well, it’s just hidden.
What you can do is create your own Thread Safe function in the Anim Blueprint, and in that function, you can perform the cast. Then return the casted result. There is a sample in the Lyra project (ABP_ItemAnimLayerBase->GetMainAnimBPThreadSafe()) that does this. One of the crucial bits is that in order for this to work, the return value of the function must be named ReturnValue, or it won’t work. SO there’s some kind of interesting code behind the scenes in Property Access, but it seems to work.
So in my case, I create a function called GetLyraCharacterThreadSafe, as shown below.
Then in my ThreadSafeUpdateAnimation function, I can use Property Access, using my newly created function, to get my Ragdoll variable, as shown below:
And it seems to actually work. Be sure to pay attention to the Pure and Thread Safe attributes when creating your functions, and again, the return value MUST be named ReturnValue, but I think this actually opens up a lot more flexibility for using the PropertyAccess functionality.
Note: I’m not smart enough to figure out if this is causing some sort of additional overhead or slowdown, and I also suspect that there’s at least the potential for errors (remember, any cast CAN fail, and I assume that will break something, but in my cast I know my cast should be a safe one). I’m also not sure this is the “official” way to do it…but there IS an example of exactly this sort of logic in the Lyra starter kit.
Would love to hear from Epic or someone with more experience if this is really the correct way. Maybe this is just something obvious to everyone else, but it took me a while to figure it out.
Really appreciate the follow-up post, saved me a ton of time!