x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to Properly Create Physics Volume for Fluid using C++?

In this project, I would like to spawn a physics volume in a sea using C++, as I am manually modifying sea level in the code. The code below can spawn the physics level. However, it is not working correctly, as my character is supposed to swim whenever it overlaps with the Physics Volume. (IsSwimming from NavMovementComponent = false even after the character enters the physics volume, should be true instead).

     //OceanSpawnLocation/OceanSpawnRot is a FVector value of where the ocean locates/rotates in.
     //Boxsize is the FVector size of the Ocean.
     FActorSpawnParameters PhysicsVolumeSpawnParams;
     APhysicsVolume* PhysicsVolume = GetWorld()->SpawnActor<APhysicsVolume>(APhysicsVolume::StaticClass(), OceanSpawnLocation, OceanSpawnRot, PhysicsVolumeSpawnParams);
     PhysicsVolume->SetActorScale3D(BoxSize);
     UWorld *World = GEditor->GetEditorWorldContext().World();
     UCubeBuilder* CubeBuilder = Cast<UCubeBuilder>(GEditor->FindBrushBuilder(UCubeBuilder::StaticClass()));
     CubeBuilder->X = oceanVolumelengthX;
     CubeBuilder->Y = oceanVolumeWidthY;
     CubeBuilder->Z = oceanVolumeHeightZ;
     CubeBuilder->Build(World);
     GEditor->Exec(World, TEXT("BRUSH ADDED"));

Below is the Settings of the Physics Volume while playing. If I manually add the physics volume using the same settings below without using the C++ code, the character would swim properly.

alt text

alt text

Any suggestions to resolving the issue would be appreciated!

Product Version: UE 4.18
Tags:
bug1.png (766.6 kB)
bug2.png (747.1 kB)
more ▼

asked Jun 18 '18 at 07:19 PM in C++ Programming

avatar image

Paul_LTC
30 3 3 9

avatar image HarryHighDef Jun 19 '18 at 12:56 PM

Do you ever set it to be a water volume?

avatar image Paul_LTC Jun 20 '18 at 04:28 PM

Yep, I do currently, and I am currently using these code:

     FActorSpawnParameters PhysicsVolumeSpawnParams;
     APhysicsVolume* PhysicsVolume = GetWorld()->SpawnActor<APhysicsVolume>(APhysicsVolume::StaticClass(), OceanSpawnLoc - deductionVector, OceanSpawnRot, PhysicsVolumeSpawnParams);
     UWorld *World = PhysicsVolume->GetWorld();
     UCubeBuilder* CubeBuilder = Cast<UCubeBuilder>(GEditor->FindBrushBuilder(UCubeBuilder::StaticClass()));
     CubeBuilder->X = oceanVolumelengthX;
     CubeBuilder->Y = oceanVolumeWidthY;
     CubeBuilder->Z = oceanVolumeHeightZ;
     PhysicsVolume->BrushBuilder = (UBrushBuilder *) CubeBuilder;
     PhysicsVolume->Brush = NewObject<UModel>(PhysicsVolume, NAME_None, RF_Transactional);
     PhysicsVolume->Brush->Initialize(PhysicsVolume, false);
     PhysicsVolume->BrushType = EBrushType::Brush_Add;
     PhysicsVolume->BrushBuilder->Build(World, PhysicsVolume);
 
     PhysicsVolume->SetNeedRebuild(PhysicsVolume->GetLevel());
     //GEditor->RebuildAlteredBSP(); For some reason, this line triggered a breakpoint, with the error: Edit and Continue : error  : 'ForestController.cpp' in 'UE4Editor-ProceduralGenerator.dll' was not compiled with Edit and Continue enabled. Ensure that the file is compiled with the Program Database for Edit and Continue (/ZI) option.

With the last commented line, the code crashes with breakpoint. Without the last line, this still yields the same result -> Scaled CubeBuilder without isSwimming functionalities.

Sometimes, this whole thing also returns a weird error: BrushComponent0 has to be 'Movable' if you'd like to move.

Any further suggestions to resolving the issue would be appreciated!

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

I've found a workaround - To manually create a PhysicsVolume in the UE Editor, set it to movable, and then set its location and scale.

     TSubclassOf<APhysicsVolume> classToFind;
     classToFind = APhysicsVolume::StaticClass();
     TArray<AActor*> foundPhysicsVolume;
     UGameplayStatics::GetAllActorsOfClass(GetWorld(), classToFind, foundPhysicsVolume);
 
     foundPhysicsVolume[0]->SetActorScale3D(BoxSize);
     foundPhysicsVolume[0]->SetActorLocation(OceanSpawnLoc - deductionVector);
 

Feel free to comment below if you've found a solution directly addressing to my problem, without manually creating a PhysicsVolume.

more ▼

answered Jun 20 '18 at 11:13 PM

avatar image

Paul_LTC
30 3 3 9

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question