Set Blackboard Value as Object

I feel like this should be the easiest thing in the world, but I can’t for the life of me figure out why it isn’t working. I have an object (an actor to be exact) that exists in the scene. I use a cast to call to reference it, then a set blackboard value as object call.

That’s it. This is a behavior tree task, for the record, that I’m working in. When I play the game and check the behavior tree, the object is always invalid. I’m assuming the cast failed then? I have know idea why.

TargetActor is just a generic Actor Object Reference variable. I’m utterly confused why this doesn’t work since I’ve used casting in other blueprints before. For the time being, I’m casting to the player character for testing purposes but it’s not always going to be like that. I need to get another AI character which is why I’m not just using the Get Player Character function.

I guess the next question is this. If I want to set some blackboard values that are constant, is there an easier way? I feel like this should be the most basic of basics. I’d honestly stick the variables into the character blueprint themselves if it weren’t for the fact that the behavior tree relies on the blackboard.

EDIT: Ok, so I tried changing TargetActor to GetPlayerCharacter(0), which worked so I guess it was a type mismatch. But both are ultimately objects, so that’s kind of odd.

The TargetLocation key is still invalid though, which makes even less sense. The GetActorLocation call has worked for me for ages

How do you set your TargetActor variable’s value? If this is a behavior tree task, then I can’t really see how that would work. Mind that BT nodes are map-agnostic, so the only way to use level-specific actors is to dynamically look for them.

Another thing to check is the runtime value of Target and TargetLocation BB key selectors. Please double-check if they’re pointing at valid BB keys of proper type.

I highly encourage you to use blueprint debugging tools (namely breakpoints and mousing over pins to check their values) - you would instantly noticed if the cast was failing.

Hope it helps, and let me know if you have any more questions.

Cheers,

–mieszko

I think I fundamentally misunderstood how casting works then. I was looking at tutorials for how to reference different objects between blueprints and casting to an object was an option. I’d assumed that I could also use it as a sort of “get this object call”. Apparently not. Duly noted.

Also, I wasn’t aware that BTs were map agnostic. In which case, it seems like getting an certain object would be incredibly inefficient. The example I was looking at used a multi sphere trace for objects and set it to ignore all AI characters in order to find the player. But that sounds a lot more expensive than I thought it’d be just to get a single actor.

You’d have to keep track of a growing array of actors to ignore if you kept adding more characters of different classes but all of the same base class, wouldn’t you? Plus I’d essentially have to make the radius big enough to cover the whole level.

I guess my real question is, is there any way to set a default BB value? Kind of like how in other blueprints, you could declare a public variable and then literally just choose an instance of that variable by setting it in the Details panel. Like how you can do for box triggers and such. Or searching by tags in other blueprints.

Or is that impossible because of how BTs are map agnostic, so they don’t have any knowledge of actors in the level? Is there no way to give them some default values without dynamically searching through all actors for the one you want?

EDIT: Also, I tried testing the set TargetLocation (I checked, it’s a vector) and hard coding a vector in (100,10,10) and it still says invalid? I completely deleted all the other nodes. The task is just Event Recieve Execute->Set Set Value as Vector → Finish execute. But when I check the BT it still says invalid. That part confuses me much more, because I think I’m misunderstanding how BB keys are set fundamentally at this point.

Ok, so for the time being I’ve decided to just store these variables in the character blueprint itself, which DOES exist in the map so it can reference other objects in the map. Then I just grab the owner, cast it to the controller I want, grab the controlled pawn, cast it again to the character type I want, and access the variable directly like that. Then I can set the BB keys using those variables. It’s not too bad, but I am punting around a lot of variables, which in general is sometimes bad coding practice but I think this is the simplest way I could think of. It works too :smiley: