[4.2] Something very wrong with swimming, movement mode never changes to "Swimming" when entering water volume

Dear Friends at Epic,

I have read all the prior swimming threads, and I have my water volumes set up correctly.

Additonally, swimming was working perfectly in 4.1.1 !

After upgrading to 4.2, now when I enter a water volume, I have a per-tick read out showing me that the movement mode is never switching to “Swimming”

It stays as “walking” the whole time!

#Readout Code

void ASolusBasePlayerController::PlayerTick(float DeltaTime)
{
	Super::PlayerTick(DeltaTime);
	
	//~~~ FPS ~~~
	CalcFPS();
	
	//~~~ Player Input ~~~
	SolusProcessPlayerInput();
	
	
	//physics??!
	if(C_SolusChar)
	{
		VShow(C_SolusChar->CharacterMovement->GetMovementName());
	}
}

Above is always showing Walking, even in water volume.

#Repro

Set up a water volume

Run into it

In both first and third person templates my character just gets stuck

#Pitch

I did try adding pitch to the forward movement function, that did not help.

void ASolusBaseCharacter::MoveForward(float Value)
{
	if (Value != 0.0f)
	{
		// find out which way is forward
		const FRotator Rotation = GetControlRotation();
		FRotator YawRotation(Rotation.Pitch, Rotation.Yaw, 0);

		// Get forward vector
		const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);

		// add movement in that direction
		AddMovementInput(Direction, Value);
	}
}

#Manually Setting to Swimming = Can’t Move Still

If I set movement mode to Swimming every tick,

I can’t move!

void ASolusBasePlayerController::PlayerTick(float DeltaTime)
{
	Super::PlayerTick(DeltaTime);
	
	//~~~ FPS ~~~
	CalcFPS();
	
	//~~~ Player Input ~~~
	SolusProcessPlayerInput();
	
	
	//physics??!
	if(C_SolusChar)
	{
		//Manually Set to Swimming every single tick
		C_SolusChar->CharacterMovement->SetMovementMode(MOVE_Swimming);
		VShow(C_SolusChar->CharacterMovement->GetMovementName());
	}
}

The output does show the char movement as “Swimming”

I can jump while character is outside of the water volume

but as soon as character enters water volume even jumping does not work and character is completely stuck against the ground.

#Thanks!

Any ideas?

Thanks!

Rama

Hi,

This does indeed sound like a bug and I’ve filed an issue (#338912) to take a look at it!

As an addendum to this topic, I did get swimming to work, but when the character is close (touching) to a wall and I try to move up/down (or diagonally up/down, facing the wall a bit), my character gets stuck. I also get stuck when I am touching the ground and try to swim forward. I am using ShooterGame as my template.

(Rama, I did revise my code to see if I could help you, but I couldn’t notice anything special I did to enable swimming. I just set the physics volume WaterVolume = true, friction to 0.0, and the character’s movement buoyancy to 1.4 and NavAgentProps.bCanSwim = true, although the latter is just for pathfinding I believe.)

“NavAgentProps.bCanSwim = true” is actually required, or CanEverSwim() returns false and we never switch to swimming mode. I should probably default that to true for convenience.

As for why you can’t deflect off surfaces when swimming, that looks like it regressed a long time ago, but should be easily fixable. If the StepUp() fails, there should be an attempt to SlideAlongSurface() instead. Flying mode used to have this problem as well. I’ll make that change.

“NavAgentProps.bCanSwim = true”

I did actually set this to true but it didnt’ help :slight_smile:

Great to hear from you Zak and Tom and Ixiguis!

Thanks Ixiguis for looking into this!

:slight_smile:

Please let me know Tom and Zak when this matter has reached some kind of conclusion, Solus is heavily dependent on swimming functionality

I just submitted some fixes to swimming, CL 2110723. They should make it to 4.3.

ue4 - Fix various issues with swimming in CharacterMovementComponent.

  • Fix lack of SlideAlongSurface() code when StepUpFails, or when it isn’t going to help (now very similar to Flying implementation).
  • CanEverSwim() wasn’t checked for various workflows (initially starting in a water volume, or when landing after falling).

I wasn’t able to repro the issue with the movement mode not changing that Rama was having, as long as I set bWaterVolume and bCanSwim correctly. Rama I suggest putting a break in UCharacterMovementComponent::PhysicsVolumeChanged() or your derived version of it and seeing why it’s not switching the movement mode.

okay thanks Zak!

I will see how things are going in 4.3 and proceed from there!

Great to hear from you!

Rama

You could also try grabbing the change on GitHub and applying the changes to your own movement component (so you don’t have to rebuild the engine) to try it out. Copy/pasting the edited functions might work :slight_smile:

Thanks for the great idea Zak!

:slight_smile:

#:heart:

Rama

I have tested today’s master build and the problem I had with sliding along surface is gone. However my character was still unable to jump out of water. ShouldJumpOutOfWater() returns true, but CheckWaterJump() doesn’t.

The problem is that it doesn’t takes into consideration BSP surfaces (which is where I was testing). To solve this, in CheckWaterJump() I replaced:

if ( HitInfo.GetActor() && !Cast<APawn>(HitInfo.GetActor()) )

with

if ( bHit && !Cast<APawn>(HitInfo.GetActor()) )

By the way, the default OutOfWaterZ was too low for me, I had to set it to 800.

Good idea :slight_smile:

https://github.com/EpicGames/UnrealEngine/pull/249

oh very interesting!

Thanks for sharing Ixiguis!

Great that you found a solution!

Do I smell a Github pull request incoming?

:slight_smile:

Thanks! I’ll take a look at it.

Hello All,

Here is a video of a good way to set up your initial water mesh and volume:

After getting your setup complete there are a few more things needed so when you enter the volume the characters physics are changed to swimming mode and you are able to move around freely.

Steps to follow:

  1. Open up your level blueprint and make sure your volume is selected in the editor.
  2. Right click in your event graph and with the volume selected create an “OnActorBeginOverlap” event.
  3. From there pull off a node from the execute pin and create a Cast To “MyCharacter” (or whatever your character blueprint is named).
  4. From the “As MyCharacter C” create a “Get Character Movement” node.
  5. From the “Cast To MyCharacter” execution pin create a “Set Movement Mode”
  6. Change the movement mode from the dropdown box to Swimming
  7. Connect the “Character Movement” node to the target pin of the “Set Movement Mode”
  8. Now go into your Project Settings and click on the “Input” section.
  9. Add a new Axis Mapping and label it something like SwimUp.
  10. Bind your desired keys in which you want the character to swim vertically.
  11. Set one of the keys to 1.0 to swim up and the other to -1.0 to swim down.
  12. Now go into your “MyCharacter” blueprint EventGraph and create a new “InputAxis” node and find the Input axis you labeled SwimUp
  13. Pull off a pin from the execution of “InputAxis” and create a new “Add Movement Input”
  14. Set the world direction values to X = 0.0, Y = 0.0, and Z = 1.0
  15. Connect the “Axis Value” from the “InputAxis” to the “Scale Value”
  16. Compile and save your blueprint.
  17. Finally go into your “MyCharacter” blueprint and within the defaults tab type in the search box “Buoyancy” and set it to a value above 1.0
  18. I set mine to 1.1 but you can experiment with this value at a later time.
  19. Test your water volume to see if it works!

Compile and Save your work. I have attached three images in order to help you with the set-up process

Let me know if this helped fix your issue or if you need further assistance.

Thanks!