4.8 CameraShake broken (c++)

Since unreal upgrade to 4.8,of c++ camera shake seems to be broken.

Hope someone can fix this. Thx.

Hey -

Do you have additional information on how it’s broken? Can you post the code where you’re using camera shake? Additionally, a short video of what you’re experiencing will help us understand exactly what’s happening.

Cheers

Well, you can grant at code from another’s post here →

However, the only solution provided was ‘using BP instead of c++’. Something we couldn’t do. Hope you fix this soon.

Hey -

I was able to solve the issue with the code setup in the post you linked to. You can check the solution there to see if that helps you with your project.

Cheers

Sigh… so you would force us to make a UPROPERTY out of UCameraShake?
What happen if my UCameraShake is code generated? And there could so many of them playing at the same time? As I said beforemI don’t want a BP solution. Right now C++ side seems to be broken

:confused:

This is my code which used to work in 4.7:

UCameraShake* nCameraShake = UCameraShake::StaticClass()->GetDefaultObject();

/* do stuff like editing its new propoerty*/

nPlayerControl->ClientPlayCameraShake(nCameraShake->GetClass(), 1.f);

The fact that that method worked in 4.7 may have actually been a bug. As I mentioned in the answer on the other post, in this case you are calling ClientPlayCameraShake and passing in the base CameraShake class rather than the nCameraShake object that you’ve made changes to. Since it is using the base class it will use the base class defaults instead of your changes. Using the blueprint was simply the easiest solution, something else you can try would be to create your own class (MyCameraShakeClass) based on UCameraShake and then make your nCameraShake a subclass of that and change the defaults in your MyCameraShakeClass. I have not tested this method however it should work as the code equivalent of using the blueprint.

Ok, so if I don’t want any to change any defaults but create each one with unique properties, how do I do that?. I’m asking you this since most of the time my CameraShake is code generated in real time, and I can’t have one Shake change the defaults properties of the others.

Hey -

Without looking at the code directly the best suggestion I can give would be to make a function that you can pass the default values to when you want to do a camera shake. If the defaults are passed into the same function then you can define the parameters of each camera shake by which values get passed to the function. The function then sets defaults and calls camera shake as explained in the other post. Again without seeing how your code is being implemented I can’t say how effective this would be in your case.

Cheers

The way I look at it, changing defaults of a base object and pass the same thing over and over to a function is hardly ideal. Can’t you make the

ClientPlayCameraShake( TSubclassOf< class UCameraShake > Shake)

into this? (Or at least a new function)

ClientPlayCameraShake( UCameraShake Shake)

That way we can just create a new object and pass it in.

ps. here’s the code:

UCameraShake* nCameraShake = NewObject<UCameraShake>();
nCameraShake->LocOscillation.X.Amplitude= x;
nCameraShake-LocOscillation.X.Frequency = y;
nPlayerControl-ClientPlayCameraShake(nCameraShake->GetClass(), 1.f);

It’s the “GetClass()” that prevents us from doing wonderful thing here.

Right now, we just have to go to BP and create new default shake every single time. Not very c++ supportive here…

In fact, speaking from c++ view, CameraShake shouldn’t even be an UObject in the first place…

Hey -

If you create a class based on CameraShake (CustomShake) and make nCameraShake a child class/subclass of CustomShake then you can write a function in CustomShake that takes in the values you want to use when ClientPlayCameraShake() is called. So prior to calling nPlayerControl-ClientPlayCameraShake(nCameraShake->GetClass(), 1.f); you can call this SetDefaults() function. You would still have to pass in the default values to be set but unless you have more than one camera shake playing at a time, this would offer better performance than having to create a new object and set its defaults every time you wanted the camera shake to play.

There is SetDefaults() function? I failed to find it anywhere in the UE document.

How do I implement it?

Sorry for not being clearer. I was referring to “SetDefaults” as a custom function that you can create/call to set defaults based on how you want the camera shake to react. Since you mentioned having different situations where the camera shake is different, it would be easiest to create a function that sets the necessary values based on what is passed into the function when it is called.

Err… I’ve tried that.

However, whenever I tried to set new values before passing in my new cameraShake class, nCameraShake->GetClass() always revert back to the initial value declared in construction script.

Thus, there’s really no way to dynamically set defaults with c++. That’s why I’m complaining about this GetClass() stuff in the first place.

So anyway to solve this?

Hey -

nCameraShake->GetClass() returns the initial values because the ClientPlayCameraShake() function takes in a TSubclassOf which will always return the default of the specified class. You can check the answer in the following link for more information on this:

If you have multiple camera shake effects with different settings, the only answer I’ve found would be to have different UCameraShake blueprints (each with their own defaults set) along with different TSubclassOf. Inside your player blueprint you can assign each of the TSubclassOf variables to a different blueprint default and then in the code when you call ClientPlayCameraShake you pass in the appropriate TSubClassOf variable.

Cheers

Yeah, so back to my point that since 4.8 we can’t dynamically create any useful shake from c++.

As mentioned previously, the implementation that worked previously may have been incorrect functionality. Since ClientPlayCameraShake() takes a TSubclassOf, I iwill put in a request to be able to edit the class defaults through code or allow the function call to accept an object pointer.