Skip to content

Add callback Action<> to SpawnManager.InstantiateAndSpawn() between Instantiate() and SpawnWithOwnership() #2832

Open
@CodeSmile-0000011110110111

Description

Is your feature request related to a problem? Please describe.

When using the convenient helper InstantiateAndSpawn there is no way to initialize components of the object before OnNetworkSpawn runs.

Specifically, this does not allow to set the initial value of a NetworkVariable so that the clients can read the intended value in OnNetworkSpawn rather than having to wait until a OnValueChanged event occurs.

But it is also relevant for initializing non-synchronized properties that the server may need to use during OnNetworkSpawn events.

For these cases one currently cannot use InstantiateAndSpawn at all, which limits its usefulness quite a bit.

Describe the solution you'd like

A callback Action (or Action) should be an optional parameter that allows one to do this:

´InstantiateAndSpawn(obj, ... , (instance) => { /* use instance to initialize components before spawn */ });´

The callback Action<> is invoked after Instantiate() and right before SpawnWithOwnership().

Describe alternatives you've considered
There's no alternative besides changing from the helper method back to manual Instantiate, assigning transform values, initializing components, and then calling SpawnWithOwnership. Essentially unwrapping the helper method.

See also my forum post here with code example changing from InstantiateAndSpawn to doing it all manually again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stat:awaiting-responseAwaiting response from author. This label should be added manually.type:featureNew feature, request or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions