Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gameplay entered/exited signals and notification issues #56494

Closed
m4nu3lf opened this issue Jan 4, 2022 · 13 comments
Closed

Gameplay entered/exited signals and notification issues #56494

m4nu3lf opened this issue Jan 4, 2022 · 13 comments
Assignees
Milestone

Comments

@m4nu3lf
Copy link
Contributor

m4nu3lf commented Jan 4, 2022

Godot version

3.4.2 stable

System information

OS: Arch Linux, CPU: Ryzen 5, GUP: RX 480

Issue description

There are two maybe related issues with gameplay entered/exited signals and notifications.

  • Notifications seem just never to work.
  • Signals work, but they don't if there is an exterior room.

Steps to reproduce

I have attached a minimal reproduction project with a roaming mesh instance that moves between two rooms. The print statements for notifications are never executed. The print statements for signals are not executed, but if the ExteriorRoom room group is deleted they will be triggered.

Note that I have not used any portals, but I assume this should work regardless. I have portals in my project, and I get the very same issue.

Minimal reproduction project

roaming_gamplay_callback_issue.zip

@Calinou Calinou added this to the 3.5 milestone Jan 4, 2022
@Calinou Calinou changed the title [Godot 3.x] Gameplay entered/exited signals and notification issues Gameplay entered/exited signals and notification issues Jan 4, 2022
@Calinou
Copy link
Member

Calinou commented Jan 4, 2022

cc @lawnjelly

@lawnjelly
Copy link
Member

After a bit of debugging, you may be a little embarrassed, but the problem is you are moving your test box in the wrong direction. 😀

rooms

If you look at your situation, you have an exterior room (0), a room that the camera is in on the left (1) and a room that the box starts in (2).

In order to enter gameplay, the box from room (2) has to enter room (1) where the camera is, as there are no portals so it operates only on the rooms that objects are within. For this to happen the box has to move left in the diagram and x must be decreased, however the script is setup so that the x coordinate increases with each frame. Thus the box moves around of room 2 into room 0, then off to infinity, but never enters room 1.

The reason it appears to work when you delete the exterior room is that once the box moves to the right into "no man's land", I can't remember exactly what happens but it may pick some default room like zero, which may coincidentally be the one in which the camera is.

If you change the script to move the box correctly to the left, it works. 👍

On the plus side though this project did show up that #37626 is spamming warnings in some situations. I did mention at the time I wasn't sure that warning PR was a good idea.

@lawnjelly
Copy link
Member

Closing as this seems to be a problem in the MRP rather than an engine bug.

@m4nu3lf
Copy link
Contributor Author

m4nu3lf commented Jan 5, 2022

@lawnjelly I was convinced to have reproduced the issue in my main project. Now I managed to find the root cause of the issue in my main project though.
The problem there is that I'm using the signals gameplay entered/exited on a visibility notifier, but the visibility notifier, while it gets notifications it doesn't trigger signals. Is this intentional?

@lawnjelly
Copy link
Member

lawnjelly commented Jan 5, 2022

Ah yes this may be true.

Having a look, it looks like VisibilityNotifier is hard coded to only receive Notifications from the gameplay monitor, and not signals (no matter your project setting). This is because in most cases users will be using the in built functionality of VisibilityNotifier.

However, this in turn creates the appropriate Screen Entered and Screen Exited signal in the VisibilityNotifier, so you should be able to use this instead if you want to use signals. Here is the code which triggers them, in the same way as VisibilityNotifier usually works when objects enter and exit the screen:

		case NOTIFICATION_ENTER_GAMEPLAY: {
			_in_gameplay = true;
			if (cameras.size() && Engine::get_singleton()->are_portals_active()) {
				emit_signal(SceneStringNames::get_singleton()->screen_entered);
				_screen_enter();
			}
		} break;
		case NOTIFICATION_EXIT_GAMEPLAY: {
			_in_gameplay = false;
			if (cameras.size() && Engine::get_singleton()->are_portals_active()) {
				emit_signal(SceneStringNames::get_singleton()->screen_exited);
				_screen_exit();
			}
		} break;

There is no signal in the case where a VisibilityNotifier enters gameplay but is not in the view frustum (this tallys in because VisibilityNotifiers aren't intended to do anything except when they are in view).

The logic is thus:
Object must be both in view AND in gameplay to send "screen entered", and if either become false it is "screen exited" etc.

I'll try and add this to the docs as it isn't clear in this particular case.

It would in theory be possible to send both the notification AND signal in this case, but I think if you wanted the gameplay signal you could maybe put this on a script for the MeshInstance rather than the VisibilityNotifier. Let me know if this is a problem though because it can be changed if there isn't an easy way around this - some situations like this aren't immediately obvious during development and if we can make things easier in use with simple changes, that is worth doing.

@m4nu3lf
Copy link
Contributor Author

m4nu3lf commented Jan 5, 2022

@lawnjelly Thanks for the clarification. In my project, I also want to know if a visibility notifier is in the gameplay even though it is not on screen. This is because my spawner logic uses visibility notifiers, but also I want to spawn some entities if the player is close enough but only if the visibility notifier is in the gameplay area.
I have simply created a script to make use of those notifications.

@lawnjelly
Copy link
Member

I have simply created a script to make use of those notifications.

Yup I think on reflection this is probably a good compromise in your situation, because modifying the engine to send signals and notifications for this special case won't be very efficient, and we are after all doing all this for greater performance.

So I guess we can say it is possible already, but just not documented yet. 👍

@m4nu3lf
Copy link
Contributor Author

m4nu3lf commented Jan 19, 2022

@lawnjelly I think I found a real bug this time. I have noticed that the gameplay_entered/gameplay_exited signals are not called when:

  1. You have a scene with an external room.
  2. The active camera is inside the external room.
  3. You switch to another scene (optional).
  4. You switch to the same scene as before with the camera starting in the external room.

The first time you load the scene you get the callback, but not at step 4. It seems clear to me that some state is being retained if you unload a scene with a portal system and a camera active.
The only workaround I found for the issue is to add the following steps after step 2:

2.a) Deactivate/delete the active camera and do not activate any other camera.
2.b) Wait for at least two idle frames.

Not too pretty, but it works in my case as the loading screen starts with a black screen so, the two black screen frames are not noticeable.

Here is the MRP which I derived from the previous one:

roaming_gamplay_callback_issue.zip

If you look at the root node you should see the workaround. Remove that and you only get the signal/notifications for "gameplay entered" the first time only.

@lawnjelly
Copy link
Member

Yes it's possible I'm not sending gameplay exit signals when the room system is unloaded, more interesting is not sending the entered signal. There is probably something that just needs a reset, am investigating. 👍

@akien-mga
Copy link
Member

Fixed by #57033.

@m4nu3lf
Copy link
Contributor Author

m4nu3lf commented Jan 24, 2022

@lawnjelly I believe I found another related issue. The "gameplay_exited" signal is not triggered for the "exterior" RoomGroup (although the gamplay_entered is triggered when you "re-enter" the exterior room. I think this is important because it is what the tutorial says it should be used to toggle directional lights or other exterior exclusive stuff.
Here is the MRP
exterior_gamplay_exited_issue.zip

@m4nu3lf
Copy link
Contributor Author

m4nu3lf commented Jan 24, 2022

@lawnjelly Actually it's a general problem for very room/roomgroup, not just the "exterior" one

@lawnjelly
Copy link
Member

Ah I've figured it out, there is a bug, there's an optimization to prevent processing unless it changes rooms, but that isn't keeping the active room ids up to date. Should be quite easy to solve. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants