pescadorrr 17 Posted June 6, 2022 I need the code to delete a item. I make a task with a trigger linked him and i need to delete a object when actívate. I have achieved that a second task is activated to the players when finishing the first task and i need delete a object. The code for the second task assigned is this: class pista_Class: SCR_BaseFactionTriggerEntity { override void OnActivate(IEntity ent) { super.OnActivate(ent); BaseWorld world = ent.GetWorld(); IEntity entity = world.FindEntityByName("tarea_2"); SCR_BaseTask task = SCR_BaseTask.Cast(entity); FactionKey m_sAssignedFaction = "US"; Faction targetFaction = GetGame().GetFactionManager().GetFactionByKey(m_sAssignedFaction); task.SetTargetFaction(targetFaction); } }; "Tarea_2" is the name of the second task. Thanks for the help. Share this post Link to post Share on other sites
SovietKitKat 4 Posted June 7, 2022 One thing you could try is to get the entity's parent and remove the entity from its children. IEntity ent = ... ent.GetParent().RemoveChild(ent); I doubt this is best practice and may leave the entity straggling in memory, but it should get the job done. I haven't tested this code myself, but it should work as long as the parent isn't null for some reason. 1 Share this post Link to post Share on other sites
joemac90 16 Posted June 8, 2022 (edited) You could try this, it deletes the entity on the server and can be called by the owner entity itself to delete it: // Note: The entity needs an RPL component, m_Owner is the entity to be deleted. SCR_EntityHelper.DeleteEntityAndChildren( m_Owner ); or SCR_EntityHelper.DeleteChildren( m_Owner ); Edited June 8, 2022 by joemac90 additional info 1 Share this post Link to post Share on other sites
pescadorrr 17 Posted June 9, 2022 On 6/7/2022 at 9:23 PM, SovietKitKat said: One thing you could try is to get the entity's parent and remove the entity from its children. IEntity ent = ... ent.GetParent().RemoveChild(ent); I doubt this is best practice and may leave the entity straggling in memory, but it should get the job done. I haven't tested this code myself, but it should work as long as the parent isn't null for some reason. This option gives an error and does not work, thanks anyway This opcion works: IEntity docus = world.FindEntityByName("documentos"); SCR_EntityHelper.DeleteEntityAndChildren( docus ); Thanks for the anwers. Share this post Link to post Share on other sites
joemac90 16 Posted June 9, 2022 Yes, you have to know the entity you want to delete. Share this post Link to post Share on other sites