C++ : bIsActive UE 5.1

Hello,

I am currently adapting the C++ code of an old plugin that I had bought and which is not kept up to date.

This plugin was written to work with Unreal Engine version 4.22 and my goal is to adapt it to work with Unreal Engine 5.1.

Thanks to my internet research, I was able to adapt most of the code. However, one last line of code is causing me trouble and I can’t find a solution.

Here is the line of code that is causing the error (header .h):

virtual void SetActive(bool bNewActive, bool bReset = false) { bIsActive = bNewActive; }

The returned error is as follows:

Error C2248: UActorComponent::bIsActive’ cannot access private member declared in class ‘UActorComponent’

To note, my knowledge of C++ is very limited. It is thanks to Google that I was able to fix the rest of the code.

Would you know how to fix this line so that my plugin finally works with UE5.1?

Thank you.

Hi DMRoyal,

It looks like bIsActive was moved from “protected” to “private”.

You can call the method SetActiveFlag(); to set it from SetActive().

1 Like

Hi RecourseDesign,

Thank you for your response, I looked at the Unreal Engine documentation about SetActiveFlag() to be able to use it, but it is not very clear.

So I modified my code:

OLD CODE:

.h

virtual void Activate(bool bReset = false) { SetActive(true); }  
virtual void Deactivate() { SetActive(false); };  
virtual void SetActive(bool bNewActive, bool bReset = false) { bIsActive = bNewActive; }

.cpp

if (!bIsActive)  
return;

NEW CODE:

.h  

virtual void Activate(bool bReset = false) { SetActiveFlag(true); }  
virtual void Deactivate() { SetActiveFlag(false); };  
void SetActiveFlag(const bool bNewIsActive) {};  

.cpp  

if (!SetActiveFlag)  
return;

I have no idea if what I did is correct, even if I no longer have a compilation error.

What do you think about that?

EDIT:

I spoke too soon.

Indeed, I do have an error in my .cpp and it is logical:

C2276 ‘!’: illegal operation on bound member function expression

So I’m lost again

I was thinking along the lines of:

virtual void SetActive(bool bNewActive, bool bReset = false) { SetActiveFlag(bNewActive); }

If the plugin has code for the Activate and Deactivate, setting it there too then yes, replace anywhere that has “bIsActive=x” with “SetActiveFlag(x)” where x is True or False…

2 Likes

Oh nice, I understand the logic! Thank you very much for your help.

I wouldn’t want to abuse your kindness, but now, how should I replace my condition in the cpp?

if (!bIsActive)  
return;

Before, I was checking if bIsActive was false. But now how should I do this check?

2 Likes

That’s with “IsActive()”

1 Like

Obviously! I should have found out by myself.

Thank you infinitely for your help, everything works perfectly thanks to you.

1 Like