I’m stuck on something and hoping someone has a suggestion. I have lots of collision classes: bullets, ships, ground, etc… And collision is working great for almost everything.
There’s just one collision that won’t work, ship vs ground. Ships collide with bullets correctly, ground collides with bullets correctly, and so on. But that one combination of ship and ground refuses to work.
Obviously, I have a typo somewhere, but I have looked for hours and can’t find it. What is really confusing me is that every other combination works. That means that my collision shapes are good.
is what I have tried:
Calling SetCollisionResponseToAllChannels(ECR_Block) for both ships and ground, to make sure it’s not an issue with a specific channel
Changing from OnComponentHit.AddDynamic() to OnComponentBeginOverlap.AddDynamic() to see if overlaps work (they don’t)
All possible values of ECollisionEnabled in SetCollisionEnabled()
Setting bGenerateOverlapEvents
Setting up collision in BeginPlay() instead of the constructors
And still nothing. I can post code if there’s some particular part that would help. I’m just looking for an idea of where to start debugging because this has really stumped me.
The only gotcha I can think of is if you are changing these settings in code, but are using a blueprint in the level that may have overriden the settings. I’d check the collision setting on the objects in-game to verify its ok.
One thing to watch out for, and I’ve had this issue any of times. You place an actor in the world via Blueprints, you save the level, change some defaults in your C++ class, recompile and try again and nothing happens. It’s because your placed actor doesn’t update its variables, you should delete the actor and place it again.
Yes, it’s there, and it looks like that code is correct…
Good idea, should have thought of that.
It’s a procedural ground made up of tiles. So each tile is an actor, created with SpawnActor(), with a single mesh component. I set the collision settings on the UStaticMeshComponent.
Good idea, but they’re all spawned from C++ with SpawnActor().
I’m going to double check these suggestions, then I’m going to just revert the code back a few days and start over.
I ripped it all out, typed it all in from scratch, still no luck.
is something that might be a hint… the first time I add the code, I hit the following assertion failure:
DelegateSignatureImpl_Variadics.inl, line 1192, method “__Internal_BindDynamic”
ensureMsgf(this->IsBound(), TEXT("Unable to bind delegate to '%s' (function might not be marked as a UFUNCTION)"), *InMacroFunctionName);
I hit that same assertion that the first time I tried, but I just kind of overlooked it because it went away. It hits once but then seems to go away when I rebuild.
Anyone else run into that assertion?
EDIT: I checked the obvious suspect and the function is marked as UFUNCTION().
I’ve tried everything that I can think of. I verified that all collision channel settings are correct in game, as and AusPaco suggested. Ship is set to block ground and ground is set to block ship.
I put debug output text in every “OnHit()” function of every actor. Sure enough, when a bullet hits the ground, I see “bullet_xxx hit ground_yyy” and when a bullet hits the ship, I see “bullet_xxx hit ship_yyy.” But no output is ever generated for ship vs ground.
I enabled “Show Collision” in the console and I can see that the collision shapes are exactly where they should be and they are very clearly overlapping.
Perhaps it’s in your movement code and not your collision. I would suggest possibly changing your Ship’s Collision to “Block All” and do some tests, if it’s not working still that would tell you it’s probably not a collision issue as Block All should do just that. You can also try Overlap All, which should call Overlap Events if it’s setup right.
Just out of curiosity - are you attaching anything to ship by welding? I’ve had all sorts of issues with that - including collision issues. If you are, try not attaching anything so there is no welding and see if collisions now work correctly.
, I tried what you suggested and the ship passes through some things but not others. Ships pass through other ships, ships pass through the ground, but bullets collide correctly with ships (and ground). Does that suggest a problem with movement?
… where “velocity” and “rotation” are just variables computed each tick. So I don’t know if that’s a common approach, but I didn’t use any “movement components,” etc…
Sorry, what’s welding? The ship is made up of a few different actors. The root is an empty USceneComponent. I do this because the player can build his ship at run-time.
The other actors (those shapes that you see in the image) are attached to the ship’s root using AttachRootComponentTo() and I position them with GetRootComponent()->MoveComponent().
If there’s a better way to attach actors to actors, please let me know and I’ll try it.
, I’m also struggling trying to get something similar working and it’s driving me INSANE. I tell you this so you know you’re not alone. Maybe we can get a discount on group therapy?
If you are just using the default arguments of AttachRootComponentTo, then you aren’t welding, so it’s probably not that.
The only thing I can think of to try is to reset your collision settings on the ship after you attach something. Does the ship collide with the ground if you DON’T attach anything, ie, just the base mesh?
Good idea, AusPaco, I tried resetting the collision channels after attachment but it didn’t make a difference.
But your suggestion made me think of something… I have these attached actors and I’m moving the root with the “sweep” parameter set. That “sweep” might not propagate to the attached actors.
So I did some searching and that might be the case:
In that thread, Tom S says: we do not perform collision sweeps sub-components when detecting collisions with characters.
That certainly seems like what I’m seeing, however, he’s talking about “characters” and I’m not using a character class.
Still, this is almost certainly the problem, so, the question becomes how do I work around this? I really need these actors to sweep.
Zak M says: when we sweep a component in MoveComponent(), we only sweep the root component and then teleport attached children
That is really, really, really unfortunate. I need a workaround for this.
Can I somehow grab the collision shapes from the attached actors and move them up to the root actor?
Another idea would be to not attach the other actors and move them all individually (this sounds awful).
Is this something I could patch in the engine code? I’ve never modified the engine code, is it difficult?
This won’t work because A) I don’t think the engine supports it and B) I wouldn’t know which actor was colliding because all the collision shapes would belong to the root
This is exactly as horrible as I expected it to be… I lose all the benefits of attachment, I would have to calculate all relative rotations and movements manually, it’s a nightmare
I could really use some advice from someone at Unreal on this… any chance that this will be implemented in 4.8?
In your case, the only thing I can think of would be to have a different collision mesh for each different configuration, and then use that as the root. Not pretty… but it should work.
That’s the approach I’m trying, but the player is free to build pretty much any shape imaginable. Is there a way to build collision shapes dynamically from C++?
Have a look at welding - it’s an option when you attach components. My understanding is that it takes your attached object, and adds it’s mesh data into the current rigidbody - ie, so you effectively have a single body. I’m not sure if it works if you aren’t simulating physics, but you could try having a root object as a collision object, and then attaching your new collision meshes directly to that with welding, to see if it works. I had some issues with welding in terms of bugs, but it may work for you
I tried setting the “bWeldSimulatedBodies” parameter to true in AttachRootComponentTo() and it didn’t make any difference. I also posted in the AnswerHub and got no response. Looks like my only option is to fix the engine, bummer.
The gist of it is just to copy the code from UPrimitiveComponent::MoveComponent() that does the “sweep” for the component. I just do that same code in a loop for all attached actors. It’s a really brute-force way to fix the problem, and I’m sure there’s a smarter way, but it’s working perfectly in my situation.
My situation is slightly different from yours, AusPaco, and different from a lot of others I’ve seen posting a similar question, but this will fix the most basic problem. It will make attached actors generate hit events, which is all that I needed. With a little more digging, you should be able to handle whatever type of collision/overlap/physics stuff you need for your attached actors.