godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.31k stars 20k forks source link

GDextension C++ scene add a autoload has effect with other scripts. #86077

Open chriztheanvill opened 8 months ago

chriztheanvill commented 8 months ago

Tested versions

Since 4.1 to current 4.2.1

System information

Godot v4.2.1.stable - openSUSE Tumbleweed 20231208 - Wayland - Vulkan (Forward+) - dedicated AMD Radeon RX 6600 (RADV NAVI23) () - AMD Ryzen 7 5700G with Radeon Graphics (16 Threads)

Issue description

Note: Every node I made it in GDextension C++ After adding a scene to autoloads, some other scenes/nodes have a weird behavior. In this case, I have a scene: Level01 made in GDextension and has the node Music (audioStream...) and set it to autoplay true. Even if I set this, Keeps playing: if (Engine::get_singleton()->is_editor_hint()) set_process_mode(Node::ProcessMode::PROCESS_MODE_DISABLED); Or my Player (also made in GDextension), the camera does not follow the player. `

Also I have a scene transition (also made in GDextensions) if I disable it in the Autoloads options, still visible.

Steps to reproduce

If I create a node with GDextension C++, then add it to a scene, save it, like:

// StoreConfigs.h
...
// StoreConfigs.cpp
if (Engine::get_singleton()->is_editor_hint()) // Tried in the Constructor or _read function, still the same
    set_process_mode(Node::ProcessMode::PROCESS_MODE_DISABLED);
...
// Compile, I use CMake to compile, my Flags:
-fno-gnu-unique -fno-exceptions -fPIC -g -Wwrite-strings -m64 -march=x86-64 
-O2 -fvisibility=hidden -m64 -fvisibility=hidden  
-fPIC -DHOT_RELOAD_ENABLED -DLINUX_ENABLED -DUNIX_ENABLED -DDEBUG_ENABLED -DDEBUG_METHODS_ENABLED -DNDEBUG -fcoroutines -pthread

// Then in Godot, Create a new Scene > Other Node > StoreConfigs > Save the Scene
// Then Project > Project Settings > Autoload and Add the StoreConfigs Scene.

Minimal reproduction project (MRP)

Could be posible with a started project, just add a scene with the steps that I listed and happens.

bs-mwoerner commented 8 months ago

Not sure I understood this correctly, but if you want to stop the audio, you should just call the AudioStreamPlayer's stop() method. I think calling set_process_mode() on the AudioStreamPlayer or one of its ancestors does nothing, because it just handles starting and stopping the audio and doesn't do much "processing" in Godot's "do something once per frame" sense.

chriztheanvill commented 8 months ago

Not sure I understood this correctly, but if you want to stop the audio, you should just call the AudioStreamPlayer's stop() method. I think calling set_process_mode() on the AudioStreamPlayer or one of its ancestors does nothing, because it just handles starting and stopping the audio and doesn't do much "processing" in Godot's "do something once per frame" sense.

In the Level Cpp script the music (audioStreamer...) the autoplay is on, but I set:

// Level00
if (Engine::get_singleton()->is_editor_hint()) // Tried in the Constructor or _read function, still the same
    set_process_mode(Node::ProcessMode::PROCESS_MODE_DISABLED);

So, even if I dont start the game: F5 or Run Project the music starts.

// ---

Also, I have made a script that made transitions made in Cpp, if in the Autoload options, if I disable it, still working: image image

bs-mwoerner commented 8 months ago

So you're saying that the AudioStreamPlayer is part of your level and has Autoplay enabled and you want it to start playing when the scene loads and

If that's the case, then something in StoreConfigs.tscn might interfere with the audio player.

Also, since your screenshot is cut off just above the Autoplay property, please note that Playing and Autoplay are two different things. Playing is just the current (preview) state. Setting that in the Editor won't affect what happens when you run the game.

chriztheanvill commented 8 months ago

So you're saying that the AudioStreamPlayer is part of your level and has Autoplay enabled and you want it to start playing when the scene loads and

  • if StoreConfigs.tscn is not set up as an Autoload, then the music plays when the game is started,
  • if StoreConfigs.tscn is set up as an Autoload, then the music does not play when the game is started?

If that's the case, then something in StoreConfigs.tscn might interfere with the audio player.

Also, since your screenshot is cut off just above the Autoplay property, please note that Playing and Autoplay are two different things. Playing is just the current (preview) state. Setting that in the Editor won't affect what happens when you run the game.

Mmm ... the thing is: Right now in the Level00 cpp I set to music autoplay to true. also I have this in the Level00 cpp

// Level00.cpp
if (Engine::get_singleton()->is_editor_hint()) // Tried in the Constructor or _read function, still the same
    set_process_mode(Node::ProcessMode::PROCESS_MODE_DISABLED);

While Not running the game: pressing F5 or Run Project.