Page MenuHomeFeedback Tracker

SetObject in EOnInit crashes WB
Assigned, NormalPublic

Description

A simple SetObject in EOnInit crashes WB after you restart WB and load into the world for the first time. Looks like different Meshes to set crash more often than others. Somewhat random. This is in a new and empty project. I also sent the crash report with the link of this ticket.
Here the Component I used:

class SetObjectTestClass : ScriptComponentClass
{
}

class SetObjectTest : ScriptComponent
{
	[Attribute("", UIWidgets.ResourcePickerThumbnail, "", "et")]
	protected ResourceName m_sPrefabToTakeMeshFrom;

	//------------------------------------------------------------------------------------------------
	VObject GetPrefabVObject(ResourceName prefab)
	{
		IEntityComponentSource itemComponentSource = SCR_BaseContainerTools.FindComponentSource(Resource.Load(prefab), "MeshObject");
		if (!itemComponentSource)
			return null;
		
		ResourceName resourceNameObject;
		itemComponentSource.Get("Object", resourceNameObject);
		if (!resourceNameObject)
			return null;
		
		return Resource.Load(resourceNameObject).GetResource().ToVObject();
	}	
	
	//------------------------------------------------------------------------------------------------
	override void EOnInit(IEntity owner)
	{		
		VObject vobject = GetPrefabVObject(m_sPrefabToTakeMeshFrom);
		if (!vobject)
			return;

		owner.SetObject(vobject, "");	
	}

	//------------------------------------------------------------------------------------------------
	override void OnPostInit(IEntity owner)
	{
		SetEventMask(owner, EntityEvent.INIT);
	}
}

If you set the mesh with this:

	//------------------------------------------------------------------------------------------------
	override void _WB_AfterWorldUpdate(IEntity owner, float timeSlice)
	{
		if (m_NewVObject)
			owner.SetObject(m_NewVObject, "");
	}

you get no mesh or a random debug mesh instead of the new mesh or it also crashes the WB

Details

Severity
Crash
Resolution
Open
Reproducibility
Random
Operating System
Windows 10 x64
Category
General
Steps To Reproduce
  1. Use the script above to try and SetObject in EOnInit
  2. Crash

Event Timeline

TheBonBon updated the task description. (Show Details)Nov 27 2023, 3:52 PM
Geez changed the task status from New to Assigned.Nov 28 2023, 10:50 AM