Converting a pointer to TSubclassOf ?

Hello,

I’ve been trying to do dynamic Camera shakes in C++.

I have:

	UPROPERTY() UCameraShake* CameraShake;

	CameraShake = NewObject<UCameraShake>(this, UCameraShake::StaticClass());
	CameraShake->OscillationDuration = 0.5;
	CameraShake->RotOscillation.Pitch.Amplitude = 1;
	CameraShake->RotOscillation.Pitch.Frequency = 20;
	//etc

However the function to play a camera shake looks like this

Controller->ClientPlayCameraShake(TSubclassOf<UCameraShake>);

How can I convert my pointer into a TSubclassOf? Because I want to set the camera shake values dynamically, I don’t want to make 100 camera shake blueprints in order to use TSubclassOf.

I tried using CameraShake->GetClass(), but that returns the default class without any of my value changes.

Is there any other way I can modify the CameraShake values in C++?

Thanks!

All you need to do is pass it a pointer to a child of UCameraShake. For your purposes, you would do it by simply passing it your CameraShake.

Here’s the Documentation regarding TSubclassOf.

Just passing in the pointer doesn’t work, which is why I posted. It gives the following error:

cannot convert from UCameraShake * to TSubclassOf<UCameraShake>

The documentation looks like it only works with an unitialized class, rather than an initialized object pointer. Unless I’m doing something wrong. Any thoughts?