I’m working on a simple game in UE 5.2 and I’m having trouble getting a reference to my Seeker AI Class in Blueprints.
In the level Blueprint, I’m wanting to print to the viewport (just using Print String for prototyping) whether the AI is currently seeking or resting to give the player visibility. However, with the following Blueprint script I have, BP Seeker is returning none resulting in runtime errors.
The ‘m_bCanSeekerSee’ variable is in C++ and I’m using the current value of that to print to the screen by getting the class as a target. I can’t figure out why BP_Seeker is returning None. Am I meant to cast it to BP_SeekerAIController or something?
Hey! This may sound stupid, I don’t think I’m setting the variable anywhere in BP. I thought it would automatically know the class as I’ve set it to the type BP_Seeker, but it seems like I’m very mistaken. I’ve achieved the above in C++, but doing it via BP is something I was messing around with.
Not stupid. By creating the BP Seeker variable and specifying the class, to use C++ terms, you’ve created a variable of type BP_Seeker but you haven’t initialized it or pointed it to an existing instance. Hence, you have your variable but it is currently null/none/invalid.
So you’ll need to set it to the instance that’s being used in your level, perhaps directly or on Event BeginPlay or something else, depending on how you have things set up.
Oh right of course… little oversight on my part . So I assume I’d need to ‘Set’ it in the Blueprint itself to initialize it. So something like Set(BP_Seeker) → BP_Seeker Class or something along them lines?
So I assume I’d need to ‘Set’ it in the Blueprint itself to initialize it.
That’s correct. If you already have an instance of the Bp_Seeker class in your level, you should be able to assign it directly to the variable (in your level blueprint, select your variable in the variables list, then in the Details(? Not at my PC at the moment) panel, you can set a default value there and should see your existing instance in the list.
Or you can spawn an instance directly in the blueprint and assign it to your variable there. Depends on what you need.