I’m pretty new to c++ and I’m trying to create a function in a third player script to check if the player is aiming before firing. My right mouse button has a Focus input and my left mouse button has a Pull trigger input. Pull Trigger is a c++ function that calls Fire on my fire component Script. I would like to create an if statement to check if the Focus input is pressed before I can fire, or an IsAiming Boolean that checks this and then checking if its true in PullTrigger before I can Fire, whichever is the simplest.
Anyone knows how to get the input in C++ to do that?
You don’t need to get the input in C++ to do that.
You can create a bool called “IsAiming” in C++ and expose it to blueprints (via UPROPERTY). Then you can set it in the blueprint when Focus is handled, and get it in the C++ function in an if-statement.
That said, I’m not sure I understand what you’re doing exactly. It sounds a bit convoluted. You get the input event in blueprints, call into C++ to pull the trigger, and that calls back into blueprints (“fire component script”)?
Oh thanks! I think I made this but backwards. I created my IsAiming bool in blueprint then I was unable to call it in C++. I guess the other way around would work!
Yeah I used a C++ template for firing but the rest is blueprint. I keep it that way because I don’t wanna start all over again. The C++ script also calls Fire for the AIs.
Ah yes. I have a lot of C++/BP interaction for my AI as well. If you need info, UPROPERTY is pretty straight forward and fairly well documented.
Yeah thanks. I just need to figure out which type of UPROPERTY gets me to set the bool. BlueprintReadOnly only lets me get it, BlueprintEditDefaultsOnly lets me see it in the defaults and set it to true or false from there and BlueprintCallable asks me for a subclass. I wish I was better at C++
BlueprintCallable is for UFUNCTION.
Yep! Just found it!! Thank you so much that will help a lot in the future I’m sure!!
Cool. And yeah, I use this strategy a LOT.