How to create a Function in C++ with return type Bool?

Hello Everyone! I need some help )
How to create this function in C++ which has a return type bool…

Hi Alexa.kl,

Here’s an example in another Forum post - he’s asking a separate question, but the code that’s used there looks like a good example:

1 Like

Thank You very much for the reply.
I got an idea from the post is:

	virtual void RollingSteering (bool& InScope);

Please correct me if I am wrong. Thank You )

1 Like

That is one way to do it - the passed in bool will be set to the correct value on return.

Another way you can do it which doesn’t need a bool passed into the UFUNCTION is:

   virtual bool RollingSteering();

And in your c++ part, it would “return ‘myBool’;” as the last statement in the function.


Thank You very much, it help me a lot… Thank You for helping me in my learning progress )

1 Like

Can I pass float and other data types in this function?
such as

   virtual bool RollingSteering(float Axis, FRotator SteeringRotator);

Yes you absolutely can - it can be very useful to do so.

When passing in values such as FRotators and FVectors - rather than pass it directly like that, it is better practice to pass a reference to it instead (then, the parameter stack is filled with just pointers to the objects rather than the objects themselves which can be quite large).

So you can do either:

virtual bool RollingSteering(float Axis, FRotator& SteeringRotator);
virtual bool RollingSteering(float Axis, const FRotator& SteeringRotator); // doesn't allow it to change


Thank You for sharing the knowledge, it really helps me and others to learn.
Thank You very much.