[ModAPI] Scripts attached to Character are lost when player respawns

Gwindalmir shared this bug 12 months ago
Considered

Here's the issue:

I have a modapi gamelogic script attached to the player's character (IMyCharacter).

When spawning in, the script is properly attached, however if the player respawn, the script is not re-attached to the new entity.


STR:

  1. Load into world with script mod (place medbay if there isn't one).
  2. Notice message displayed on screen from mod
  3. Press backspace and respawn
  4. Select medbay and respawn.
  5. Wait about 15 seconds (for old body to disappear), and notice the message just stops.


The script should be recreated and attached to any subsequent entity that matches automatically, just like any other entity (blocks, for example).

I've attached the mod, but the script is super simple:

using Sandbox.Definitions;
using Sandbox.ModAPI;
using VRage.Game;
using VRage.Game.Components;
using VRage.ModAPI;
using VRage.ObjectBuilders;

namespace Phoenix.TeamColors
{
    [MyEntityComponentDescriptor(typeof(MyObjectBuilder_Character), false)]
    public class PlayerSkin : MyGameLogicComponent
    {
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
        }

        public override void UpdateBeforeSimulation100()
        {
            var character = (Container.Entity as VRage.Game.ModAPI.IMyCharacter);
            if (character != null)
            {
                MyAPIGateway.Utilities.ShowNotification($"Character: {(character.Definition as MyCharacterDefinition).Id}");
            }
        }
    }
}

Comments (1)

photo
1

Hello, Engineer!


Thank you for your feedback! Your topic has been added between considered issues.Please keep voting for the issue as it will help us to identify the most serious bugs.


We really appreciate your patience.


Kind Regards

Keen Software House: QA Department