Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CodeSmile-0000011110110111 opened this issue Feb 27, 2024 · 0 comments
Labels
stat:awaiting triage Status - Awaiting triage from the Netcode team. type:feature New feature, request or improvement

Comments

@CodeSmile-0000011110110111
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting triage Status - Awaiting triage from the Netcode team. type:feature New feature, request or improvement
Projects
None yet
Development

No branches or pull requests

1 participant