ClassName::StaticClass()'s problem

//Class A
UCLASS()
class AFrameWorkCameraManager : public APlayerCameraManager
{
public:
AActor* m_pMyActor;

public:
 virtaul void Tick(float _time) override;
}

void AFrameWorkCameraManager ::Tick(float _time)
{
if(m_pMyActor)
{
//stuff somthing
}
}

and here is class B’s (.h, .cpp)

 //class B
    class B : public AActor
    {
    public:
    virtual void BeginPlay() override;
    }
    
    void B::BeginPlay()
    {
    UClass* p1 = AFrameWorkCameraManager ::staticClass();
    AFrameWorkCameraManager* p2 = ((AFrameWorkCameraManager*)p1);
    
    if(p2)
    {
    p2->m_pMyActor= this;
    }
    
    }

I thought beginplay Function is called before Tick Function

So, class AFrameWorkCameraManager’s Tick

if(m_pMyActor) will be not “NULL” i thought

but, that value was NULL;

what’s going on?

what is my mistake?

condition : class B cant have class AFrameWorkCameraManager as member value.

You code looks really wierd, how do you set pOtherActor? Also what the heck is this mostrosity :stuck_out_tongue:

 UClass* p1 = AFrameWorkCameraManager ::staticClass();
 AFrameWorkCameraManager* p2 = ((AFrameWorkCameraManager*)p1);

If you want to spawn actor use ()->SpawnActor(p1);

wow, thanks to .
your answer was so nice to me, helpful!

anyway…

I wirte here all i intended

first step is here

  1. many Camera Actors is set in MyLevel

Second step.

class AFrameWorkCameraManager has TArray (use add function)

it will be assigned many Camera Actor in Level ( at Camera Actor’s C++ Script BeginPlay Function)

but!! one problem appeared

I can’t access to AFrameWorkCameraManager in Camera Actor class’s function

so, I find staticClass() Function as Problem Answer

like upper code

upper code is sample, but principle is same

last step is

  1. I choice One Actor Camera in Array (AFrameWorkCameraManager)
    and this Actor Camera will be Target (use SetViewTarget)

i have crash in second step

pOtherActor Set code is there

if(p2)
{
p2->pOtherActor = this;
}

Obviuesly you have problem in step 2, and it’s not because something is null but it’s because invalid cast (thats why i called monstrocity :p)

UClass* p1 = AFrameWorkCameraManager ::staticClass();
AFrameWorkCameraManager* p2 = ((AFrameWorkCameraManager*)p1);

StaticClass() return UClass* which is class identifier (which you can use to spawn for example), it is not a object of a class, so you can’t cast it to object pointer. All this can be replaced withone line

AFrameWorkCameraManager* p2 = Cast<AFrameWorkCameraManager>(GEngine->GetFirstLocalPlayerController()->GetCameraManager());

Also didn’t i told you to use ViewTarget insted on other quastion? I told you it a lot easier

yep, i will use ViewTarget like other question(thanks you veryful).

but before use that function.

i have to have some Camera Actor in CameraManager(TArray)

this Question is about that flow.

i try to this code

AFrameWorkCameraManager* p2 =
Cast(GEngine->
GetFirstLocalPlayerController()->GetCameraManager());

but can not find "GetCameraManager"Function

ah i find “PlayerCameraManager”

God bless you.
It work! also ViewTarget

are you there…?

so sorry say to that…

after SetViewTarget PlayerController by

GEngine-> GetFirstLocalPlayerController(()) ->SetViewTarget(CamActor),

I cant controll My Actor

any key input stop like w,s,a,d

I think SetViewTarget just View Target, not character possess
so, Character still origin position

Thats wierd, i dont see any possession, or else your code use view target for controls.

Try setting bAutoManageActiveCameraTarget to false in player controller, it will make setting view target 100% manual, that mean if you possess pawn it wont set that pawn as a view target.

Also make sure you use GetPawn() to interact with pawn in controller