I am adding a component to BasePlayer.
When the plugin is loaded using hot load everything works as it should. But if I reload the plugin with the "o.reload" command, the component is removed and not added.
namespace Oxide.Plugins
{
[Info("ComponentTest", "Test", "1.0.0")]
class ComponentTest : RustPlugin
{
class TestClass : MonoBehaviour {}
[ChatCommand("ttt")]
void TestCommand(BasePlayer player)
{
if (player.HasComponent<TestClass>()) Puts("Player has component.");
else Puts("Player has no component!");
}
void OnServerInitialized()
{
foreach (BasePlayer player in BasePlayer.activePlayerList)
{
player.GetOrAddComponent<TestClass>();
}
}
void Unload()
{
foreach (BasePlayer player in BasePlayer.activePlayerList)
{
TestClass component;
if (player.TryGetComponent(out component)) UnityEngine.Object.Destroy(component);
}
}
}
}
How to reproduce the problem:
I load the plugin using hot load (by saving it from the editor).
I enter the test command "ttt" and see a message in the console that the player has a component.
Then I reload the plugin with the command "o.reload".
I enter the command "ttt" again and see that the player has no component.
If I reload again with the command "o.reload", the component will appear.