<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.thedarkmod.com/index.php?action=history&amp;feed=atom&amp;title=Spawn</id>
	<title>Spawn - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.thedarkmod.com/index.php?action=history&amp;feed=atom&amp;title=Spawn"/>
	<link rel="alternate" type="text/html" href="https://wiki.thedarkmod.com/index.php?title=Spawn&amp;action=history"/>
	<updated>2026-04-29T18:04:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.thedarkmod.com/index.php?title=Spawn&amp;diff=6666&amp;oldid=prev</id>
		<title>Greebo: /* Spawning Entities from a Script */</title>
		<link rel="alternate" type="text/html" href="https://wiki.thedarkmod.com/index.php?title=Spawn&amp;diff=6666&amp;oldid=prev"/>
		<updated>2008-07-03T12:05:04Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Spawning Entities from a Script&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 12:05, 3 July 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l9&quot;&gt;Line 9:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 9:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To spawn a new entity via a map script, run this code&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To spawn a new entity via a map script, run this code&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  entity newGuard = sys.spawn(&amp;quot;atdm:ai_merc_elite&amp;quot;);&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  entity newGuard = sys.spawn(&amp;quot;atdm:ai_merc_elite&amp;quot;);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;which will spawn an elite &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;mercenery &lt;/del&gt;(at the world origin &amp;lt;0,0,0&amp;gt;, to be precise, which is probably not what you want, but that&#039;s not the subject here). The call will tell the SDK to spawn a new entity with the given &#039;&#039;entity class name&#039;&#039;. The corresponding SDK function is &amp;lt;tt&amp;gt;idGameLocal::SpawnEntityDef()&amp;lt;/tt&amp;gt;, which will take care of the rest.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;which will spawn an elite &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;mercenary &lt;/ins&gt;(at the world origin &amp;lt;0,0,0&amp;gt;, to be precise, which is probably not what you want, but that&#039;s not the subject here). The call will tell the SDK to spawn a new entity with the given &#039;&#039;entity class name&#039;&#039;. The corresponding SDK function is &amp;lt;tt&amp;gt;idGameLocal::SpawnEntityDef()&amp;lt;/tt&amp;gt;, which will take care of the rest.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== idGameLocal::SpawnEntityDef ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== idGameLocal::SpawnEntityDef ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Greebo</name></author>
	</entry>
	<entry>
		<id>https://wiki.thedarkmod.com/index.php?title=Spawn&amp;diff=6665&amp;oldid=prev</id>
		<title>Greebo: /* idGameLocal::SpawnEntityDef */</title>
		<link rel="alternate" type="text/html" href="https://wiki.thedarkmod.com/index.php?title=Spawn&amp;diff=6665&amp;oldid=prev"/>
		<updated>2008-07-03T07:49:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;idGameLocal::SpawnEntityDef&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 07:49, 3 July 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l38&quot;&gt;Line 38:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 38:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;When C++ programmers look at the Spawn() function declaration, they might start wondering how this is possible with the Spawn() method being actually &amp;#039;&amp;#039;&amp;#039;non-virtual&amp;#039;&amp;#039;&amp;#039; (compare game/entity.h):&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;When C++ programmers look at the Spawn() function declaration, they might start wondering how this is possible with the Spawn() method being actually &amp;#039;&amp;#039;&amp;#039;non-virtual&amp;#039;&amp;#039;&amp;#039; (compare game/entity.h):&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  void	Spawn();&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  void	Spawn();&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It happens like this: Instead of making the &amp;lt;tt&amp;gt;idEntity::Spawn()&amp;lt;/tt&amp;gt; virtual and relying on the subclasses to pass the Spawn() call up to the base class, id software chose to implement some trickery to make this happen automatically. Therefore, it&#039;s important to note that &#039;&#039;you don&#039;t need to call the base class in the derived class&#039; spawn function&#039;&#039;. Behind the scenes, this is handled in a recursive function &amp;lt;tt&amp;gt;idClass::CallSpawnFunc&amp;lt;/tt&amp;gt; which inspects the (also home-grown) type information and calls the Spawn function pointer manually at each level.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It happens like this: Instead of making the &amp;lt;tt&amp;gt;idEntity::Spawn()&amp;lt;/tt&amp;gt; virtual and relying on the subclasses to pass the Spawn() call up to the base class, id software chose to implement some trickery to make this happen automatically. Therefore, it&#039;s important to note that &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;&#039;&#039;you don&#039;t need to call the base class in the derived class&#039; spawn function&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;&#039;&#039;. Behind the scenes, this is handled in a recursive function &amp;lt;tt&amp;gt;idClass::CallSpawnFunc&amp;lt;/tt&amp;gt; which inspects the (also home-grown) type information and calls the Spawn function pointer manually at each level.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&#039;&#039;Note:&#039;&#039; the same applies to the idEntity::Save and idEntity::Restore routines. You don&#039;t need to save the base classes during saving and loading, if your class is actually deriving from idEntity.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&#039;&#039;Note:&#039;&#039; the same applies to the &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;tt&amp;gt;&lt;/ins&gt;idEntity::Save&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/tt&amp;gt; &lt;/ins&gt;and &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;tt&amp;gt;&lt;/ins&gt;idEntity::Restore&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/tt&amp;gt; &lt;/ins&gt;routines. You don&#039;t need to save the base classes during saving and loading, if your class is actually deriving from idEntity.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{sdk}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{sdk}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Greebo</name></author>
	</entry>
	<entry>
		<id>https://wiki.thedarkmod.com/index.php?title=Spawn&amp;diff=6664&amp;oldid=prev</id>
		<title>Greebo: /* idGameLocal::SpawnEntityDef */</title>
		<link rel="alternate" type="text/html" href="https://wiki.thedarkmod.com/index.php?title=Spawn&amp;diff=6664&amp;oldid=prev"/>
		<updated>2008-07-03T07:46:59Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;idGameLocal::SpawnEntityDef&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 07:46, 3 July 2008&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l17&quot;&gt;Line 17:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 17:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  SpawnEntityDef(&amp;quot;atdm:ai_merc_elite&amp;quot;) =&amp;gt; entityDef atdm:ai_merc_elite =&amp;gt; &amp;quot;spawnclass&amp;quot; = &amp;quot;idAI&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  SpawnEntityDef(&amp;quot;atdm:ai_merc_elite&amp;quot;) =&amp;gt; entityDef atdm:ai_merc_elite =&amp;gt; &amp;quot;spawnclass&amp;quot; = &amp;quot;idAI&amp;quot;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The next steps are:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The next steps are:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;# Set a new name for this entity (each entity&#039;s name must be unique in the game)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;# Apply the difficulty settings to the entity&#039;s spawnargs (this happens in TDM only)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Find the C++ class with that name and create a new instance&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Find the C++ class with that name and create a new instance&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Call the Spawn() function of the entire class hierarchy&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;# Call the Spawn() function of the entire class hierarchy&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The first &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;step &lt;/del&gt;is rather easy&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. Due &lt;/del&gt;to a number of code macros&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/del&gt;each C++ entity class has a name, which can be looked up in some kind of dictionary. Given the class was actually found, the &amp;lt;tt&amp;gt;CreateInstance()&amp;lt;/tt&amp;gt; function is invoked on that class, which allocates the memory required by that class and calls the C++ constructor. The constructor is also registering the entity in the idGameLocal structures and performs a few other organisational tasks to link the new object.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The first &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;two steps are relatively easy and straightforward, just look at the code and you&#039;ll see what&#039;s going on. &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Finding the C++ class &lt;/ins&gt;is &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;also &lt;/ins&gt;rather easy&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;: thanks &lt;/ins&gt;to a number of code macros each C++ entity class has a name, which can be looked up in some kind of dictionary. Given the class was actually found, the &amp;lt;tt&amp;gt;CreateInstance()&amp;lt;/tt&amp;gt; function is invoked on that class, which allocates the memory required by that class and calls the C++ constructor. The constructor is also registering the entity in the idGameLocal structures and performs a few other organisational tasks to link the new object.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Note that the class &amp;#039;&amp;#039;&amp;#039;idAI&amp;#039;&amp;#039;&amp;#039; is actually deriving from &amp;#039;&amp;#039;&amp;#039;idEntity&amp;#039;&amp;#039;&amp;#039;, which is the base class for all entities. The inheritance scheme for idAI is at the time of writing:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Note that the class &amp;#039;&amp;#039;&amp;#039;idAI&amp;#039;&amp;#039;&amp;#039; is actually deriving from &amp;#039;&amp;#039;&amp;#039;idEntity&amp;#039;&amp;#039;&amp;#039;, which is the base class for all entities. The inheritance scheme for idAI is at the time of writing:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Greebo</name></author>
	</entry>
	<entry>
		<id>https://wiki.thedarkmod.com/index.php?title=Spawn&amp;diff=6663&amp;oldid=prev</id>
		<title>Greebo: New page: Spawn is a term describing the &quot;birth&quot; of an entity in the game world. Multiplayer gamers are probably familiar with the term &#039;&#039;respawn&#039;&#039;. Entities are the only objects which are able ...</title>
		<link rel="alternate" type="text/html" href="https://wiki.thedarkmod.com/index.php?title=Spawn&amp;diff=6663&amp;oldid=prev"/>
		<updated>2008-07-03T07:42:47Z</updated>

		<summary type="html">&lt;p&gt;New page: Spawn is a term describing the &amp;quot;birth&amp;quot; of an &lt;a href=&quot;/index.php?title=Entity&quot; title=&quot;Entity&quot;&gt;entity&lt;/a&gt; in the game world. Multiplayer gamers are probably familiar with the term &amp;#039;&amp;#039;respawn&amp;#039;&amp;#039;. Entities are the only objects which are able ...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Spawn is a term describing the &amp;quot;birth&amp;quot; of an [[entity]] in the game world. Multiplayer gamers are probably familiar with the term &amp;#039;&amp;#039;respawn&amp;#039;&amp;#039;. Entities are the only objects which are able to spawn in the first place.&lt;br /&gt;
&lt;br /&gt;
It might be interesting for you to know what happens behind the scenes when an entity spawns. This can happen at various times during runtime:&lt;br /&gt;
* When starting a new map&lt;br /&gt;
* The SDK code is spawning an entity while the game is running, e.g. when a projectile is fired / hitting a surface&lt;br /&gt;
* A script spawns a new entity&lt;br /&gt;
&lt;br /&gt;
== Spawning Entities from a Script ==&lt;br /&gt;
To spawn a new entity via a map script, run this code&lt;br /&gt;
 entity newGuard = sys.spawn(&amp;quot;atdm:ai_merc_elite&amp;quot;);&lt;br /&gt;
which will spawn an elite mercenery (at the world origin &amp;lt;0,0,0&amp;gt;, to be precise, which is probably not what you want, but that&amp;#039;s not the subject here). The call will tell the SDK to spawn a new entity with the given &amp;#039;&amp;#039;entity class name&amp;#039;&amp;#039;. The corresponding SDK function is &amp;lt;tt&amp;gt;idGameLocal::SpawnEntityDef()&amp;lt;/tt&amp;gt;, which will take care of the rest.&lt;br /&gt;
&lt;br /&gt;
== idGameLocal::SpawnEntityDef ==&lt;br /&gt;
The code in the gameLocal function SpawnEntityDef will try to look up the specified [[entityDef]] &amp;#039;&amp;#039;atdm:ai_merc_elite&amp;#039;&amp;#039;. If the entityDef is not found (i.e. it&amp;#039;s defined nowhere in the .def files) the game will exit gracefully. &lt;br /&gt;
&lt;br /&gt;
If the entityDef is found, the code attempts to read the &amp;quot;spawnclass&amp;quot; keyvalue from it. This key will tell the code which &amp;#039;&amp;#039;C++ class&amp;#039;&amp;#039; it needs to instantiate - in the case of the elite mercenary the C++ class this is &amp;#039;&amp;#039;&amp;#039;idAI&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
 SpawnEntityDef(&amp;quot;atdm:ai_merc_elite&amp;quot;) =&amp;gt; entityDef atdm:ai_merc_elite =&amp;gt; &amp;quot;spawnclass&amp;quot; = &amp;quot;idAI&amp;quot;&lt;br /&gt;
The next steps are:&lt;br /&gt;
# Find the C++ class with that name and create a new instance&lt;br /&gt;
# Call the Spawn() function of the entire class hierarchy&lt;br /&gt;
The first step is rather easy. Due to a number of code macros, each C++ entity class has a name, which can be looked up in some kind of dictionary. Given the class was actually found, the &amp;lt;tt&amp;gt;CreateInstance()&amp;lt;/tt&amp;gt; function is invoked on that class, which allocates the memory required by that class and calls the C++ constructor. The constructor is also registering the entity in the idGameLocal structures and performs a few other organisational tasks to link the new object.&lt;br /&gt;
&lt;br /&gt;
Note that the class &amp;#039;&amp;#039;&amp;#039;idAI&amp;#039;&amp;#039;&amp;#039; is actually deriving from &amp;#039;&amp;#039;&amp;#039;idEntity&amp;#039;&amp;#039;&amp;#039;, which is the base class for all entities. The inheritance scheme for idAI is at the time of writing:&lt;br /&gt;
* idEntity&lt;br /&gt;
** idAnimatedEntity&lt;br /&gt;
*** idAFEntity_Base&lt;br /&gt;
**** idAFEntity_Gibbable&lt;br /&gt;
***** idActor&lt;br /&gt;
****** idAI&lt;br /&gt;
The standard C++ code will take care that all the constructors in the inheritance chain are called, starting from idEntity downwards.&lt;br /&gt;
&lt;br /&gt;
Once the entity is allocated, constructed and registered, the Spawn() function is invoked &amp;#039;&amp;#039;on every level in the class hierarchy&amp;#039;&amp;#039;, i.e. the code calls idEntity::Spawn(), then idAnimatedEntity::Spawn(), ... and finally idAI::Spawn().&lt;br /&gt;
&lt;br /&gt;
When C++ programmers look at the Spawn() function declaration, they might start wondering how this is possible with the Spawn() method being actually &amp;#039;&amp;#039;&amp;#039;non-virtual&amp;#039;&amp;#039;&amp;#039; (compare game/entity.h):&lt;br /&gt;
 void	Spawn();&lt;br /&gt;
It happens like this: Instead of making the &amp;lt;tt&amp;gt;idEntity::Spawn()&amp;lt;/tt&amp;gt; virtual and relying on the subclasses to pass the Spawn() call up to the base class, id software chose to implement some trickery to make this happen automatically. Therefore, it&amp;#039;s important to note that &amp;#039;&amp;#039;you don&amp;#039;t need to call the base class in the derived class&amp;#039; spawn function&amp;#039;&amp;#039;. Behind the scenes, this is handled in a recursive function &amp;lt;tt&amp;gt;idClass::CallSpawnFunc&amp;lt;/tt&amp;gt; which inspects the (also home-grown) type information and calls the Spawn function pointer manually at each level.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Note:&amp;#039;&amp;#039; the same applies to the idEntity::Save and idEntity::Restore routines. You don&amp;#039;t need to save the base classes during saving and loading, if your class is actually deriving from idEntity.&lt;br /&gt;
&lt;br /&gt;
{{sdk}}&lt;/div&gt;</summary>
		<author><name>Greebo</name></author>
	</entry>
</feed>