Download

Spawn Even if Colliding

There were threads about this flag of the SpawnActor has no effect, but still no answer. I have created simple mesh and assigned Box Simplified Collision mesh to it. Then I have created blueprint with this mesh. When I am spawning two instances of this blueprint in the same location I have actually two actors spawned, despite the fact that “Spawn Even if Colliding” not flagged. I have just missed something or what?

what happen if you offset the second one a bit but still overlap?

It makes no difference.

where did you call the spawn?
if you don’t mind, show the graph as you might have hit a bug.

spawncolliding.png

This is in Level Blueprint.

Edit: Cube mesh is 20x20x20.

If this is a bug it is really old: "Spawn Even if Colliding" has no effect? - UE4 AnswerHub

Can confirm it’s a bug.

Basically this is the actually checking part. bNoCollisionFail is the check box we have.
bCollideWhenPlacing is true for Actor, and only a few like Spectator etc are set to false



if( !SpawnParameters.bNoCollisionFail && Template->GetRootComponent() && Template->bCollideWhenPlacing && Template->GetRootComponent()->ShouldCollideWhenPlacing() )
{
    // Try to find a spawn position
    if ( !FindTeleportSpot(Template, NewLocation, NewRotation) )
    {
        UE_LOG(LogSpawn, Log, TEXT("SpawnActor failed because of collision at the spawn location %s] for %s]"), *NewLocation.ToString(), *Class->GetName() );
        return NULL;
    }
}


Now on a [ROOT]static mesh component, was hardcoded to return false(lol on comments):



virtual bool ShouldCollideWhenPlacing() const override
{
    // Current Method of collision does not work with non-capsule shapes, enable when it works with static meshes
    // return IsCollisionEnabled() && (StaticMesh != NULL);
    return false;
}


on Shape(sphere/box/capsule) components:
bShouldCollideWhenPlacing is 1 hardcoded.



virtual bool ShouldCollideWhenPlacing() const override
{
return bShouldCollideWhenPlacing || IsCollisionEnabled();
}


One would think that if I use a sphere/capsule shape as root component, enable collision, and that check would be usable right?
Nope, you have to make FindTeleportSpot() return False as well. And that’s a long code to trace.(I gave up half way, at that point for anyone intended to use the flag the way they wanted, may as well develop their own cheap solution.)
The matter of fact that it tries to spawn with offset location is mind boggling, instead of just returning none when there is a collision.

Here is my simple way to avoid spawning, it was implemented in level blueprint for quick testing, but you can manage to make it better.
Choose the type of trace you want, usually a shape based sweep works better.
877cc59b4d6b9427a1d149554ca418dd6ad2778a.png

Thank you for your effort. I didn’t even think to check the code. UE4 starts to be really annoying with all this workarounds for the trivial things.

I agree, it’s a trade off between many aspects.
I found they sometimes tries to do a lot for you but not working as intended and just left it there for later, or something not even blip on the radar maybe cause problem.
(like UI overhaul to use UMG because industry standard tends to just use scaleform, and lots of people getting stomped new comer or not.)

But, it’s kinda getting there, behavior tree is pretty solid now. Animation part is also solid.(render/effect are solid from the get go I think)
Sometimes workaround are developed by people because they don’t know how it works and just try to get things done, sometimes like this thread are actually doing a much better job than the potential cost if the function work as intended.
(there are like multiple loops inside that FindTeleportLocation function)

Is there any news on a bugfix?

Have you actually posted it as a bug on answerhub? It looks like it IS a bug, so submit it there.

The problem being, it’s so long ago and I didn’t finish the trace.
I don’t know if it’s still there.

Just checked on github, the related code I posted above is still exactly the same.(even comments.)
I should post this on answer hub as sort of bug/feature request. Spawn even if colliding flag. - UE4 AnswerHub

For people who are interested in trace codes, here are relevant location:
/Engine/Source/Runtime/Engine/Classes/Components/ShapeComponent.h Line: 237

/Engine/Source/Runtime/Engine/Classes/Components/ShapeComponent.h Line: 32 and Line: 42

/Engine/Source/Runtime/Engine/Private/LevelActor.cpp Line: 291(this is the starting point when you leave that check box off)

Hi everyone,

I just wanted to provide a quick update here. This issue is one that we have been tracking internally (UE-3772). Unfortunately we do not have it corrected yet. Based on the post that PenguinTD submitted on the AnswerHub, I have updated the ticket to reflect that AnswerHub post, as well as this forum thread.

If it was never working, why the heck is it even available? Just to confuse people? Why was there not even a comment at the node like CURRENTLY NOT WORKING or something?

The only thing that solves this problem is setting the Collision Preset from OverlapAllDynamic to OverlapAll