Why isn't the variable being set during gameplay? (behavior tree and casting)

My code should work but it doesnt do anything, I’m simply setting a variable within my character BP from a behavior tree task (via casting). Then I’ll get this same variable in my level blueprint to use in a branch node.


The code I put a comment around doesn’t execute because the string doesn’t print on screen during gameplay.


branch node in my level blueprint, getting the variable that has just been set in behavior tree. This code is working but does not execute because the variable isn’t being set during gameplay.

Why is the variable not being set though?

Thank you for any replies

looks the like cast is failing, is you pawn of the class “spawntostartbathroomconvo”?

do a print string on the controlled pawn and it will show the display name, that should give you a clue

‘SpawnToStartConvo’ is a character blueprint and also the controlled pawn of my behavior tree. The class setting is set to type ‘character’ and it’s running the behavior tree as well:
Capture
Capture2

Should I set it to type ‘pawn’ instead?
There is no code inside the character BP except for the variable I want to set.

Do you mean to put a print string before the cast? anything before the cast executes if that’s what you’re wondering, I have no errors so I don’t understand why the cast is failing.

Here’s the rest of the behavior tree, not sure if that might have something to do with it. The task with yellow around it is the task containing the cast in question.

yep the only way the cast can fail is if the controlled pawn isnt what you think it is, so attach a print string there and see what it is.

also i dont think your sequence will complete if it succeeds since your calling finish execute on the top path

can you explain this further? I don’t understand what you mean by ‘print string and see what it is’? can you be more specific and tell me how to do this exactly.

don’t I need to call finish execute though? how else would I do it?

sorry I’m still learning

print string is a built in function, if you drag off controlled pawn and put it in a print string it will tell you what controlled pawn it is.

you do need to finish execute but your doing it before the sequences node will finish, this may be intended but if not the sequence wont complete

is this correct? when I run the game nothing is being printed

yep so that tells you either the task is never being called or the pawn is invalid which is why the cast fails. remove the get display name, if it prints hello ‘default’ the the task is being called at least

Does the blueprint type I’m casting to have to be of type ‘pawn’ it cannot be anything other than type pawn?

Yes I already said the task is running at the very start of the thread though, so how do I fix the invalid pawn? the code in this task should work though I’m assuming, it might be something to do with the way my tree is set up.

character is a child of pawn so thats fine and we’ve just establish that the pawn is null so thats strange.

what task is this in? we might need to go back a step.

id still do the print sting check, i know you say its working but until we see it, its better to be sure. cant see why the pawn would be invalid

yes I’ve only said this because I’ve already tested it and hello is printing.

I’m going to test this task in a blank behavior tree and see if its working or if there’s some problem with the tree I’m currently working on.

the rest of the tree, the one circled in yellow is the task that’s having issues