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

event CarChangedDelegate CarChanged not working as expected. #1648

Closed
SCarlsen7757 opened this issue Jul 18, 2024 · 1 comment
Closed

event CarChangedDelegate CarChanged not working as expected. #1648

SCarlsen7757 opened this issue Jul 18, 2024 · 1 comment

Comments

@SCarlsen7757
Copy link

Describe the bug
I'm trying to make a plugin that uses the CarChanged event.
But when I open R3E and start a private session the method isn't called. I have also tried starting a new private session with other cars, but it's still not called. When using the replay feature the method is called but the newCar argument is null, and it's repeat itself multiple times. The amount of time the method is called is random, at least what I can see.

namespace SimHub.Plugins;
public class PluginManager : INotifyPropertyChanged
{
  public delegate void CarChangedDelegate(string newCar, PluginManager manager);
  public event CarChangedDelegate CarChanged;
}
namespace MyCustomPlugin;
public class CustomPlugin : IPlugin, IDataPlugin, IWPFSettingsV2
{
  public void Init(PluginManager pluginManager)
  {
    pluginManager.CarChanged += PluginManager_CarChanged;
  }

  private void PluginManager_CarChanged(string newCar, PluginManager manager)
  {
      if (newCar == null)
      {
          SimHub.Logging.Current.Error($"Car changed event method. newCar argument is null.");
          return;
      }
      SimHub.Logging.Current.Info($"Car changed event method. newCar argument value: {newCar}");
  }
}

Simhub version
Simhub version 9.3.9

Third party plugins
I only have my plugin and Keyboard Input plugin active.

Expected behavior
I expected the event to be called when I change car and the event is called with valid newCar argument (not null and has the car name or ID).

Log files
SimHub.txt
SimHub.txt with debug logging

@SHWotever
Copy link
Owner

Hi ! The car changed is only raised for a car change during a session, most of the time the car change will be tied to a new session and not trigger it.

To get more systematic event about it you can use PluginManagerEvents.Instance.ActiveCarChanged this event gets triggered everytime the car changes no matter the conditions.
Then you can access the current car name here : PluginManager.LastCarId

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

2 participants