BenPyton / ProceduralDungeon

This is an Unreal Engine 4/5 plugin to generate procedural dungeon.
MIT License
527 stars 64 forks source link

Room's origin consuming collision #27

Closed SAM2WOW closed 1 year ago

SAM2WOW commented 1 year ago

Hello! I just started using this plugin and it's fantastic!

However, I did encounter an issue. I have a custom trace channel for tracing auto-lock targets in my game. However, when I generated a room, the origin prism also blocks this trace channel and causes the auto-lock to lock on it. When I print what is blocking it prints "mapname + _C." Is there any way to change the collision of this blueprint?

Thank you very much!

image

BenPyton commented 1 year ago

Hi @SAM2WOW

Can you show me your code for your line trace, please?

The prism is only a debug draw, there is nothing there (no actor, trigger, etc.) so it is not that.

However, when checking Occlude Dynamic Actors in the plugin settings, each room has a trigger box to be able to track actors entering and leaving the rooms (so the plugin can show/hide them accordingly). Your mapname_C is your level blueprint actor.

The room's trigger boxes are using a trace channel not available in blueprint only. When doing a line trace, you have to filter with for example a LineTraceByChannel node and select the channels you want (all of the channels available in blueprint if you want).

Alternatively, you can disable the Occlude Dynamic Actors in the plugin settings, so the room's trigger boxes will not be spawned, but actors not belonging to rooms will not be occluded in occluded rooms.

Best.

SAM2WOW commented 1 year ago

Hi! Thank you so much for the explanation. Disabling the occlude dynamic actors works!

For my tracing script, I am tracing one of my custom channels called Enemy, which is ignored by default. And then I do some other filtering and checks. image

BenPyton commented 1 year ago

Hi @SAM2WOW

So I suppose your custom trace channel is colliding with the one I use in the plugin.

How many custom channel do you use? Currently in the plugin's code I'm using the ECC_GameTraceChannel18, so I suppose you are using all the 18 custom channel slots?

You should search for the text Enemy in your DefaultEngine.ini file of your project and check if it is defined as ECC_GameTraceChannel18.

If so, I should change the one in my plugin by an engine slot instead, so plugin users could use all the 18 custom trace channels in their projects.

If you are able to recompile the plugin code with Visual Studio, could you try to change the line 89 of the Source/ProceduralDungeon/Private/RoomLevel.cpp file from:

RoomTrigger->SetCollisionObjectType(ECollisionChannel::ECC_GameTraceChannel18);

To:

RoomTrigger->SetCollisionObjectType(ECollisionChannel::ECC_EngineTraceChannel6);

If this is solving your issue while Occlude Dynamic Actors setting is enabled, then I will add this fix for the next release.

Best.

SAM2WOW commented 1 year ago

Hi and thanks a lot! So I checked my settings and I'm only using 3 custom tracing channels. image

I also recompiled the plugin after changing that line of code and unfortunately, it's still able to detect the room trigger.

image I tried printing all the components that got hit and I found out it was the room trigger that got hit by the Enemy channel. I also found out that the room trigger will only get hit when there's also an enemy AI that's present in the room.

BenPyton commented 1 year ago

Okay, this is very weird... So the issue is more complex than I thought.

I will investigate further when I'll have some more times (I have no access to my pc for few days right now...)

I will come back to you when I have found something.

Best.

BenPyton commented 1 year ago

Hi @SAM2WOW

So, I have investigate in the engine code, and I found that the Multi and non-Multi versions of all the tracing functions (Line, Sphere, Box, etc.) does not have exactly the same behaviours.

In SceneQuery.cpp file of Unreal Egine, line 345 to 348:

if (Traits::SingleMultiOrTest != ESingleMultiOrTest::Multi)
{
    QueryCallback.bIgnoreTouches = true;
}

This means that the non-Multi versions does in fact ignore overlap only components (what all triggers are). While the Multi versions does not ignore them (and so returning also triggers) So, it's why I didn't have this issue when I tested my Occlude Dynamic Actor feature, since I used a non-Multi line tracing.

In the engine code, the Object Type and Trace Channel are exactly the same. They both share the same 18 game trace channels in the enum. The only difference between the two is that you can't assign a Trace Channel as an object type in editor.

I can do something for room triggers to ignore any Trace Channel, so only Object Types can overlap with the room trigger. However, even if I fix that on my side for the plugin, you will encounter your issue for any trigger you will create with an overlap (or block) response with your Enemy trace channel.

Now, I have also a solution for you in the meantime and for all situations. You can filter the actors in your hit array inside your Find Sorted Actor Closer To Center function. For example, you can discard all non-pawn actors (because in general, all enemies are pawns). image

If you have enemies that are not pawns (eg. traps or turrets) you have to create a filter accordingly. For example discarding all non-blocking hits instead of non-pawn.

I hope this solution resolves your issue.

Best.

EDIT: I've pushed the fix on the master branch (commit 66804ab). However, this fix is only for the room triggers, you will get the issue again for any other trigger with overlap or block repsonse with your Enemy channel.

SAM2WOW commented 1 year ago

Ah thank you so much!!

I was actually going to use my lock on for other actors that are not just a pawn. For now I think I could just add a node that filter out room triggers.

Thank you so much for the update! :)