Override Action which is only performed at the spawn.

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
GGianpy
Posts: 57
Joined: Wed Mar 11, 2020 3:09 pm
Graphics Processor: Not Listed
Location: Italy

Override Action which is only performed at the spawn.

Post by GGianpy »

good evening,
how can I make an actor run this code only once when it spawns?

Code: Select all

	Override void Tick()
	{
		Super.Tick();
	}
I tried onspawn(), onborn() but it doesn't work.
I found nothing on the guide ...
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Override Action which is only performed at the spawn.

Post by Jarewill »

Are you trying to call Tick() when an actor spawns, or what?
You could try overriding void PostBeginPlay. It always worked for me.
But I still am not sure what you are trying to do here.
User avatar
Caligari87
Admin
Posts: 6233
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Override Action which is only performed at the spawn.

Post by Caligari87 »

Tick() runs ... every tick. That's what it's supposed to do. You can't have it run only once or your actor will break

Best alternate solutions:
BeginPlay(): The earliest one-time override for a newly spawned actor. Not all systems may be accessible at this point.
PostBeginPlay() The next one-time override for a newly spawned actor. Most everything should be set up by the time this runs. This is the one you should probably use if you're not sure about the differences.

One more possible solution, but not necessarily recommended as it clutters up Tick() unnecessarily.

Code: Select all

Override void Tick() {
    super.Tick();
    if (getage() == 1) { //Checks if the object is exactly 1 tick old
        //One-time code to run
    }
}
The wiki page where you can find this information is [wiki]ZScript_virtual_functions[/wiki]

8-)
GGianpy
Posts: 57
Joined: Wed Mar 11, 2020 3:09 pm
Graphics Processor: Not Listed
Location: Italy

Re: Override Action which is only performed at the spawn.

Post by GGianpy »

ok thanks,
i'm new to zscript i knew "tick()" but i didn't know "beginplay()" because i didn't find anything on the wiki.
Post Reply

Return to “Scripting”