How to get reference of a custom class instance?

There are several ways to do that, could you please eloborate more, some code, what you did, what you expecting, what you want to achieve to in case of forwarding you to best solution.

Hello.

I’m struggling to get a reference of a custom class derived from AActor.
I’ve defined a pointer to this custom class :

AManipulateur* HandlingRobot;

I need to set this pointer to the instance of this class I have in my scene.

I was thinking of using :

UGameplayStatics::GetActorOfClass(),

but it returns an AActor* pointer, and not a AManipulateur* pointer.

What would be the best way to do it?
A cast? How would I set it?

Thanks for your help.

Yes, thanks for the answer.

The context :

I consider myself a begginer at C++, and have followed a few tutorials to start learning. I’m trying to use what I’ve learned so far, so I know that the way I picked is probably not the best way.

I’m trying to simulate an industrial process where I have spare parts brought on a conveyor to a robot that needs to pick them up, and place them in the scene.

I created a custom class to spawn the parts a move them on the conveyor up to the picking location.
Once they arrive, I want to tell the robot (of class AManipulateur) to go pick up the part (through a bool) and give him the target.

But to do this I need to establish a link between my spawner and the robot to be able to modify its bool and target location variables, but I don’t know how to do it.

you will do casting

AManipulateur* HandlingRobot = Cast<AManipulateur>(OtherActor)

Thanks, but how do you definie this OtherActor (tried your way, but says OtherActor is not defined)

Yes sure, its a placeholder, that means you can put there any actor while calling

uGameplayStatics::GetActorsOfClass()

Indeed, as I was saying, I’m a begginer but eager to learn.
All seems to be working. Thanks a lot for your time and answers.
If you have any recommandation to work on fundamentals I’m all ears :wink:

Thanks, that’s working, until I start compiling in UE4, and I get the error :

Spawner.cpp(21) : error C2120: ‘void’ non conforme avec tous types

On line :

AManipulateur* HandlingRobot = Cast(UGameplayStatics::GetActorOfClass(GetWorld(), ManipulateurClass));

In BeginPlay function.

Any idea?

Its AManipulateur not ManipulateurClass, mate I suggest you to work C++ fundemental.

No problem. I will guide you if you eager to learn.

Will do, thanks for the suggestion, I’ll contact you through discord if I get stuck again.