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"

Force on Static Mesh Component sometimes ignored

Hi there,

So I have an actor class which contains 1 static mesh component and code to handle some gameplay things. When spawned a force is applied to the skeletal mesh body instance like so:

 FBodyInstance* BodyInstance = StaticMeshComp->GetBodyInstance();
 if (BodyInstance && BodyInstance->IsInstanceSimulatingPhysics())
     FVector ForceVec = ForceDirection * ForceToUse;
     StaticMeshComp->AddImpulse(ForceVec, NAME_None, true);

about 90% of the time this will cause the actor to fly out with the desired physics (inc gravity), but the other 10% it will actually fail to move and just fall down with gravity as if stuck. Note that I get this using the exact same Blueprint parent, so each object is the same.

Now these actors are being spawned on a socket of the player so there is overlap between the two, however the skeletal mesh is being spawned with an overlap condition of all pawns (in fact we have gone to the extreme to fix this by making it overlap all object types, but still have the both physics and query collision enabled).

I have put logging in to ensure that the force is actually being set to a reasonable value in all cases, and it is.

If nothing is set to block this mesh, what else could be causing our actor to not actually move at all. The only component it has is the static mesh component (which is therefore the root one). Why would it work 90% of the time? What other things can I debug to try and work out what is going on here?

From my logging here you can see that it does actually initially move for the first few ticks, before it stops all X and Y movement and just falls on Z

[2017.01.10-23.54.28:373][536]Explode_Throw_C_5 - got force X=-1993.614 Y=-153.283 Z=-44.795 applied [2017.01.10-23.54.28:373][536]Explode_Throw_C_5 - Pos X=-3060.249 Y=-408.965 Z=192.741 [2017.01.10-23.54.28:381][537]Explode_Throw_C_5 - Pos X=-3078.381 Y=-410.359 Z=192.214 [2017.01.10-23.54.28:390][538]Explode_Throw_C_5 - Pos X=-3094.992 Y=-411.636 Z=191.663 [2017.01.10-23.54.28:398][539]Explode_Throw_C_5 - Pos X=-3111.601 Y=-412.913 Z=191.045 [2017.01.10-23.54.28:407][540]Explode_Throw_C_5 - Pos X=-3111.601 Y=-412.913 Z=190.977 [2017.01.10-23.54.28:416][541]Explode_Throw_C_5 - Pos X=-3111.601 Y=-412.913 Z=190.820

Where as the one before it keeps going:

[2017.01.10-23.54.26:307][294]Explode_Throw_C_4 - got force X=-1985.258 Y=-242.294 Z=-6.573 applied [2017.01.10-23.54.26:308][294]Explode_Throw_C_4 - Pos X=-2971.250 Y=-648.023 Z=193.060 [2017.01.10-23.54.26:316][295]Explode_Throw_C_4 - Pos X=-2987.792 Y=-650.042 Z=192.901 [2017.01.10-23.54.26:324][296]Explode_Throw_C_4 - Pos X=-3004.333 Y=-652.060 Z=192.675 [2017.01.10-23.54.26:333][297]Explode_Throw_C_4 - Pos X=-3023.328 Y=-654.379 Z=192.326 [2017.01.10-23.54.26:342][298]Explode_Throw_C_4 - Pos X=-3039.866 Y=-656.397 Z=191.955 [2017.01.10-23.54.26:352][299]Explode_Throw_C_4 - Pos X=-3060.559 Y=-658.922 Z=191.383 [2017.01.10-23.54.26:361][300]Explode_Throw_C_4 - Pos X=-3079.135 Y=-661.190 Z=190.784

Product Version: UE 4.13
more ▼

asked Jan 11 '17 at 12:13 AM in C++ Programming

avatar image

496 18 27 142

avatar image Doug E ♦♦ STAFF Jan 11 '17 at 03:32 PM

Hey Ben-

You said the code provided is called when the actor is spawned. Does that mean that you are calling this code in BeginPlay? What are the values of the variables used in your code? How are you calculating/setting ForceDirection, ForceToUse, PrimitiveComponent, etc.? If you're able to reproduce this behavior in a new project, please include the setup steps to help me test the issue locally and/or provide the sample project so that I can see the results you're getting directly.

avatar image Ben.Driehuis Jan 11 '17 at 11:26 PM

Hey doug, that primitive component was supposed to be StaticMeshComp, bad copy and paste there :). Its the mesh component on the projectile itself.

As you can see from the logging the force is definitely doing something initially, otherwise it wouldn't be moving in X and Y at all in those first 4 Position outputs.

From those log outputs, I am writing the value of ForceVec ( "force X=-1985.258 Y=-242.294 Z=-6.573 applied" ).. This code itself is running outside the object after it is spawned.

I also changed instead of using force, to add a projectile movement component and set the ForceVec as the velocity and setting the velocity on it like so:

 AActor* SpawnActor = (UGameplayStatics::BeginDeferredActorSpawnFromClass(this, ClassToSpawn, SpawnTransform, ESpawnActorCollisionHandlingMethod::AlwaysSpawn));
 if (SpawnActor)
     SpawnActor->Instigator = Cast<APawn>(HolderOwner);
     AUGProjectile* Proj = Cast<AUGProjectile>(SpawnActor);
     if (Proj)
         Proj->MovementComp->Velocity = ForceVec;
     UGameplayStatics::FinishSpawningActor(SpawnActor, SpawnTransform);

This exhibited the exact same behaviour. 90-95% of the actors moved correctly, the others moved for a couple frames then stopped all X and Y movement and fell like they hit an invisible wall.

And the collision on the static mesh was set to overlap all object types. So the fact it seems like its being stopped makes no sense.

Again all actors contained just a static mesh component and in this case a projectile movement component (with their updated component set to the Static Mesh component).

Note I also registered the OnProjectileStop of the projectile movement component which isn;t triggered in this case.

avatar image Doug E ♦♦ STAFF Jan 12 '17 at 06:18 PM

If this code is being ran outside of the object, where exactly does it exist / how is it being called? If you can reproduce this behavior in a new project, please include step-by-step reproduction steps, including code classes and other assets being added/created, and/or provide a sample project showing the issue.

avatar image Ben.Driehuis Jan 13 '17 at 03:40 AM

Hi Doug, So the code above shows how I am spawning it if thats what you are asking.

I was able to reproduce this in a new code project based on 4.13.2. Here is a link to the project https://www.dropbox.com/s/gxi9jfc4dlsc5zi/PhysicsBug.zip?dl=0

Note the code is a bit silly in places but its just copied from our actual project and then heavily edited to just work.

If you load the TestMap you can press mouse button to spam pots. You will notice some of them will stop right infront of you and just drop The static mesh on that throw object is set to overlap everything with simulate physics on. This case is using the projectile movement, although the code for the alternative is there too just in case.

There is logging too...

Note this only happens every now and again, sometimes it happens multiple times in a row, sometimes one in 20 to 30..

Some more info: It seems to happen more if you run with slomo 0.2, it is suddenly a lot more common. I assume its colliding with the player character but without any block , stop or hit events happening.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hey Ben-

Thank you for the sample project. The issue appears to be with the static mesh component simulating physics. I noticed that you specifically set the movement component's gravity scale to 0.0 and turned physics on for the mesh. If instead you set the scale to 1.0 and turn physics off, you will get the same behavior as the working projectiles without the mesh being blocked. This is also true for the first person template project. The arc of the projectile is controlled by the projectile's velocity and gravity scale rather than physics.


Doug Wilson

more ▼

answered Jan 13 '17 at 02:21 PM

avatar image Ben.Driehuis Jan 15 '17 at 11:08 PM

Yeah it seems to be to do with the simulation of physics, but I am not sure why its a problem... As mentioned earlier the projectile movement was an attempt to solve the problem, we were actually just applying force to the objects before. I am not sure I want to use a projectile movement component in our actual case. Using the projectile movement changes how far everything moves.

Any ideas why we are seeing it being stopped when it has no blocking collision? We have a lot of physics being applied to objects for different reasons, so we'd like to try and narrow down why in some cases the physics isn't working.

avatar image Doug E ♦♦ STAFF Jan 20 '17 at 03:24 PM

Though it is not blocking, the overlap is still interfering with the physics of your object. You can even see this yourself by setting the collision response of the static mesh's Pawn channel to Ignore. Even with physics still enabled, you will see that it is no longer being blocked by the character.

avatar image Ben.Driehuis Jan 22 '17 at 10:18 PM

Ok, so am I correct in saying that anything that blocks the object type of our actor, will block its physics even when its set to overlap?

If I told the Pawn to overlap the Actors Object Type and this Actor to overlap pawns, there would be no physics interference? Cause then we could just create a new Collision Object Type for this particular case.

Thanks for the help, it does make things more clearer

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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