Jump to content

Correct way to 'spawn' an actor? Mine is causing crashes


Harwin17

Recommended Posts

I've currently got a working Mod that changes the X2TargetingMethod on a bunch of templates and replaces them with my own to do damage preview changes. But I don't really *need* to override X2Targeting - I'm not changing targeting, just previews.

 

So I've started working on getting my mod to work without altering any templates.

 

I figured I'd Spawn an actor that could get Ticks and then it could check for ability activation and fix previews. And it works fairly well - I'm about at parity with my old behavior. But when I load my tactical map saved game from within the tactical map (after previously loading the saved game) - it hard locks.

 

I've narrowed it down to the actor creation - even if my actor does nothing (The overrided Tick function just calls Super.Tick and returns), it still causes this issue. And if my mod loads but I don't let it spawn the actor, everything is fine.

 

Any suggestions/answers as to what I'm doing wrong would be greatly appreciate.d

 

Here's the relevant spawning(modified to remove comments, whitespace, etc)

event OnInit(UIScreen Screen) {     
    if ( PreviewUpdater == none )         
        PreviewUpdater = `XCOMGAME.Spawn(class'EnhancedAOEPreview_PreviewUpdater', `XCOMGAME);
}

defaultproperties {	
    ScreenClass=class'UITacticalHUD';
}
The game crashes about 2-3 seconds after starting to load the game, long before the OnInit would be called for the load. Edited by Harwin17
Link to comment
Share on other sites

Ok, for the record, I have absolutely no idea what you're doing, but..

 

I know that defaultproperties block has funny syntax issues and writing it like this

defaultproperties {	
    ScreenClass=class'UITacticalHUD';
}

causes it to not process variables inside, so your OnInit block fires on every screen because it defaults ScreenClass to none

Instead change it to this:

defaultproperties
{	
    ScreenClass=class'UITacticalHUD';
}

(brackets on separate line).

 

I am of course not sure if this is the cause of your crash, but still..

Link to comment
Share on other sites

(brackets on separate line).

 

Sorry - they are on a separate line in my actual code. I only put them on the same line here to make the code snippet shorter. But I also didn't realize that about defaultproperties (or I'd have made it correct in the snippet), so thanks for that info.

Edited by Harwin17
Link to comment
Share on other sites

I identified the problem.

 

If I remove the assignment of the spawned result (PreviewUpdater = 'blah') then the load proceeds normally. Presumably the assignment is preventing the garbage collector from cleaning up the old actor, even though I never get an "event Destroyed" notification on the actor. It does appear to actually delete it - in the new level I only see 1 of them getting ticked, so it doesn't still have the old one around.

 

I'm not super comfortable with relying on the fact that it's auto-destroying - it would be bad if multiple of these actors existed, so instead of checking the old variable, I'm doing an AllActors test.

 

So, to the best of my knowledge, here is the way to Spawn an actor when the TacticalHUD starts up (using the UIScreenListener I previously mentioned)

foreach `BATTLE.AllActors(class'EnhancedAOEPreview_PreviewUpdater', PreviewUpdater)	
{		
    PreviewUpdaterExists = true;	
}	

if ( !PreviewUpdaterExists )	
{
    `BATTLE.Spawn(class'EnhancedAOEPreview_PreviewUpdater', `BATTLE);	
}
Edited by Harwin17
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...