Infinite Yield in `waitForComponent` During Migration from `1.2.3` to `1.3.1`

While migrating Flamework components from version 1.2.3 to 1.3.1, I encountered an issue related to the fix for "references to uninitialized components" introduced in 1.2.4. Problem: - I have a class that initializes during component startup and internally uses waitForComponent. - Due to the changes in component initialization, this now causes an infinite yield. Normally, I would pass this as an argument to avoid yield, but the class is part of the WCS library, which automatically replicates arguments passed to created classes - making it impossible to pass the component reference directly. Are there any workarounds to handle this situation? Maybe I can defer waitForComponent in a way that avoids the infinite yield?
1 Reply
Mirrox
MirroxOP2d ago
cc @fireboltofdeath I can of course just make a getter function that will get the required component, but I would like to know if it is possible to do without it, since getting it every time is at least inconvenient Component:
public onStart() {
this.handleConfig()
$print("yield")
}

private handleConfig() {
const config = this.getConfig()

this.configSkills = [
new config.WallComboSkill(this.wcs_character),
new config.AwakenSkill(this.wcs_character),
new config.BackDashSkill(this.wcs_character),
new config.SideDashSkill(this.wcs_character),
new config.FrontDashSkill(this.wcs_character),
new config.BlockSkill(this.wcs_character),
new config.AttackSkill(this.wcs_character),
new Attacking(this.wcs_character),
]

this.wcs_character.ApplyMoveset(config.baseMoveset) //Yields
}
public onStart() {
this.handleConfig()
$print("yield")
}

private handleConfig() {
const config = this.getConfig()

this.configSkills = [
new config.WallComboSkill(this.wcs_character),
new config.AwakenSkill(this.wcs_character),
new config.BackDashSkill(this.wcs_character),
new config.SideDashSkill(this.wcs_character),
new config.FrontDashSkill(this.wcs_character),
new config.BlockSkill(this.wcs_character),
new config.AttackSkill(this.wcs_character),
new Attacking(this.wcs_character),
]

this.wcs_character.ApplyMoveset(config.baseMoveset) //Yields
}
skill:
export abstract class BaseSkill<
StarterParams extends unknown[] = [],
ConstructorArguments extends unknown[] = [],
Metadata = void,
Janitor extends object | undefined = undefined,
> extends Skill<StarterParams, ConstructorArguments, Metadata, Janitor> {
protected declare serverCharacter: ServerCharacter
protected declare clientCharacter: ClientCharacter
protected declare sharedCharacter: SharedCharacter
protected declare characterConfig: CharacterConfig

protected OnConstructServer() {
const components = Dependency<Components>()
const serverCharacter = components
.waitForComponent<ServerCharacter>(this.Character.Instance)
.timeout(15)
.expect()
assert(
serverCharacter,
`Server character for player ${this.Player} wasn't found.`,
)

this.serverCharacter = serverCharacter
this.sharedCharacter = this.serverCharacter
this.characterConfig = this.sharedCharacter.getConfig()
}
}
export abstract class BaseSkill<
StarterParams extends unknown[] = [],
ConstructorArguments extends unknown[] = [],
Metadata = void,
Janitor extends object | undefined = undefined,
> extends Skill<StarterParams, ConstructorArguments, Metadata, Janitor> {
protected declare serverCharacter: ServerCharacter
protected declare clientCharacter: ClientCharacter
protected declare sharedCharacter: SharedCharacter
protected declare characterConfig: CharacterConfig

protected OnConstructServer() {
const components = Dependency<Components>()
const serverCharacter = components
.waitForComponent<ServerCharacter>(this.Character.Instance)
.timeout(15)
.expect()
assert(
serverCharacter,
`Server character for player ${this.Player} wasn't found.`,
)

this.serverCharacter = serverCharacter
this.sharedCharacter = this.serverCharacter
this.characterConfig = this.sharedCharacter.getConfig()
}
}
if I understood correctly and you asked about my code Yes, I understand, I just can't figure out how to restructure it...
Normally, I would pass this as an argument to avoid yield, but the class is part of the WCS library, which automatically replicates arguments passed to created classes - making it impossible to pass the component reference directly.
Alright, thanks for the help

Did you find this page helpful?