Page MenuHomeFeedback Tracker

EXP 1.02 - GetGame().CreateObject spawning invisible buildings
Closed, ResolvedPublic

Description

Any objects spawned using GetGame().CreateObject are not visible, however the collisions are still happening.

Details

Severity
Major
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General
Steps To Reproduce
class CustomMission: MissionServer
{	
	void SetRandomHealth(EntityAI itemEnt)
	{
		if ( itemEnt )
		{
			int rndHlt = Math.RandomInt(55,100);
			itemEnt.SetHealth("","",rndHlt);
		}
	}
	
	void SpawnObject(string objectName, vector position, vector orientation)
	{
		Object obj;
		obj = Object.Cast(GetGame().CreateObject(objectName, "0 0 0"));
		obj.SetPosition(position);
		obj.SetOrientation(orientation);
		
		// Force update collisions
		if (obj.CanAffectPathgraph())
		{
			obj.SetAffectPathgraph(true, false);
			GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(GetGame().UpdatePathgraphRegionByObject, 100, false, obj);
		}
	}

	override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
	{
		Entity playerEnt;
		playerEnt = GetGame().CreatePlayer(identity, characterName, pos, 0, "NONE");//Creates random player
		Class.CastTo(m_player, playerEnt);
		
		SpawnObject("Land_City_Hospital", pos, "149 0 0");
		
		GetGame().SelectPlayer(identity, m_player);
		
		return m_player;
	}
	
	override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
	{
		EntityAI itemTop;
		EntityAI itemEnt;
		ItemBase itemBs;
		float rand;
		
		itemTop = player.FindAttachmentBySlotName("Body");
		
		if ( itemTop )
		{
			itemEnt = itemTop.GetInventory().CreateInInventory("Rag");
			if ( Class.CastTo(itemBs, itemEnt ) )
				itemBs.SetQuantity(4);

			SetRandomHealth(itemEnt);
			
			itemEnt = itemTop.GetInventory().CreateInInventory("RoadFlare");
			SetRandomHealth(itemEnt);
			
			rand = Math.RandomFloatInclusive(0.0, 1.0);
			if ( rand < 0.35 )
				itemEnt = player.GetInventory().CreateInInventory("Apple");
			else if ( rand > 0.65 )
				itemEnt = player.GetInventory().CreateInInventory("Pear");
			else
				itemEnt = player.GetInventory().CreateInInventory("Plum");
		
			SetRandomHealth(itemEnt);
		}
	}
};

init.c snippet above:
fresh spawn player will be stuck colliding with an invisible hospital, as an example.

Event Timeline

AussieCleetus created this task.EditedMar 27 2019, 7:00 PM

Also Garden plots are invisible when they have been dug up.

This has been tested on 100% vanilla current exp build.

Sorry if I put this in the wrong report section, but it affects mods as well as vanilla.

rVn changed the task status from New to Assigned.Mar 28 2019, 11:30 AM
rVn closed this task as Resolved.Mar 28 2019, 3:56 PM
rVn claimed this task.

Fixed internally, should be in the next exp update

I'm still getting the invisible objects on the current experimental.

These tests are run on a completely vanilla exp server, with no mods. These are the only changes in init.c for testing purposes:

Object SpawnObject(string objectName, vector position, vector orientation)
{
    Object obj;
	Print("[TEST] Spawning: " + objectName + " at: <0, 0, 0>");
    obj = Object.Cast(GetGame().CreateObject(objectName, "0 0 0", true));
	Print("[TEST] Moving: " + objectName + " to: " + position.ToString());
	obj.SetPosition(position);
	Print("[TEST] Rotating: " + objectName + " to: " + orientation.ToString());
    obj.SetOrientation(orientation);
	
    // Force update collisions
	if (obj.CanAffectPathgraph())
	{
		Print("[TEST] Setting Collision for: " + objectName);
		obj.SetAffectPathgraph(true, false);
		GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(GetGame().UpdatePathgraphRegionByObject, 100, false, obj);
	}
	return obj;
}

void LoadAdditionalObjects()
{
    Object newObject;
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 13.4 3309.4", "90 0 -3");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 12.05 3329", "90 0 -5");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 10.4666 3349.05", "90 0 -4");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 9.7521 3369.52", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 9.7521 3389.52", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 9.7521 3409.52", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 9.7521 3429.52", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 9.7521 3449.52", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 8.90569 3468.58", "90 0 -5");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 7.17 3488.5", "90 0 -5");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 5.42173 3508.4", "90 0 -5");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 3.677 3528.32", "90 0 -5");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 1.93 3548.24", "90 0 -5");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 0.185 3568.15", "90 0 -5");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 -1.54738 3588.08", "90 0 -5");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 -3.29682 3607.98", "90 0 -5");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 -4.2 3628.68", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 -4.2 3648.68", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 -4.2 3668.68", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 -4.2 3688.68", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 -4.2 3708.68", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 -4.2 3728.68", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 -4.2 3748.68", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 -4.2 3768.68", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13123.5 -4.2 3788.68", "90 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13122.9 -4.2 3807.88", "86 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13121.3 -4.4 3827.38", "85 0 -1.00001");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13119.4 -4.6 3847.27", "84 0 0");
    newObject = SpawnObject("Dam_Concrete_20_Floodgate", "13117.4 -5.1 3866.64", "84 0 -3.00001");
}

void main()
{
	//INIT WEATHER BEFORE ECONOMY INIT------------------------
	Weather weather = g_Game.GetWeather();

	weather.MissionWeather(false);    // false = use weather controller from Weather.c

	weather.GetOvercast().Set( Math.RandomFloatInclusive(0.4, 0.6), 1, 0);
	weather.GetRain().Set( 0, 0, 1);
	weather.GetFog().Set( Math.RandomFloatInclusive(0.05, 0.1), 1, 0);

	//INIT ECONOMY--------------------------------------
	Hive ce = CreateHive();
	if ( ce )
		ce.InitOffline();

	//DATE RESET AFTER ECONOMY INIT-------------------------
	int year, month, day, hour, minute;
	int reset_month = 9, reset_day = 20;
	GetGame().GetWorld().GetDate(year, month, day, hour, minute);

    if ((month == reset_month) && (day < reset_day))
    {
        GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
    }
    else
    {
        if ((month == reset_month + 1) && (day > reset_day))
        {
            GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
        }
        else
        {
            if ((month < reset_month) || (month > reset_month + 1))
            {
                GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
            }
        }
    }
	Print("[TEST] Starting Loading of Additional Objects.");
	LoadAdditionalObjects();
}

class CustomMission: MissionServer
{	
	void SetRandomHealth(EntityAI itemEnt)
	{
		if ( itemEnt )
		{
			int rndHlt = Math.RandomInt(55,100);
			itemEnt.SetHealth("","",rndHlt);
		}
	}

	override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
	{
		Entity playerEnt;
		vector m_pos = "13117 1.1 3875";
		playerEnt = GetGame().CreatePlayer(identity, characterName, m_pos, 0, "NONE");//Creates random player
		Class.CastTo(m_player, playerEnt);
		
		GetGame().SelectPlayer(identity, m_player);
		
		return m_player;
	}
	
	override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
	{
		EntityAI itemTop;
		EntityAI itemEnt;
		ItemBase itemBs;
		float rand;
		
		itemTop = player.FindAttachmentBySlotName("Body");
		
		if ( itemTop )
		{
			itemEnt = itemTop.GetInventory().CreateInInventory("Rag");
			if ( Class.CastTo(itemBs, itemEnt ) )
				itemBs.SetQuantity(4);

			SetRandomHealth(itemEnt);
			
			itemEnt = itemTop.GetInventory().CreateInInventory("RoadFlare");
			SetRandomHealth(itemEnt);
			
			itemEnt = player.GetInventory().CreateInInventory("Mag_UMP_25Rnd");
			itemEnt = player.GetInventory().CreateInInventory("Mag_UMP_25Rnd");
			
			rand = Math.RandomFloatInclusive(0.0, 1.0);
			if ( rand < 0.35 )
				itemEnt = player.GetInventory().CreateInInventory("Apple");
			else if ( rand > 0.65 )
				itemEnt = player.GetInventory().CreateInInventory("Pear");
			else
				itemEnt = player.GetInventory().CreateInInventory("Plum");
		
			SetRandomHealth(itemEnt);
		}
		itemEnt = player.GetHumanInventory().CreateInHands("UMP45");
	}
};
  
Mission CreateCustomMission(string path)
{
	return new CustomMission();
}
AussieCleetus added a comment.EditedMar 29 2019, 7:09 PM

I retract that. Passing true in the 3rd parameter for CreateObject results in an invisible object if that object isn't an AI Entity. That was my error.