Spawning a different prefab depending on whether the character is controlled locally or remotely.

Hello!

I’m currently using the HLAPI, as well as the SteamVR library. I have two prefabs: one to be spawned to represent a local user; one to be spawned to represent remote users. The first prefab includes the SteamVR component, so it is only appropriate to be spawned with the local user. The second prefab is just for visually representing where the other users are located.

Both prefabs are related in the following way - They both have a script from which they inherit called ‘UserContext’. The sync variables are all in that base script. I presume that as long as all the variables that are sync’d are in the same base class, there should be no issues synchronizing them, even if they are of different sub-types.

Could someone please advise on how to achieve this ‘locality-determined’ prefab spawning with the HLAPI? I’m presuming it requires that I override the OnServerAddPlayer method, but I’ve tried doing so, and it always just spawns out the prefab that I set for the Spawn Info → Player Prefab, or nothing at all, which is not what I want.

Thank you for your time!

They need to be the same prefab since HLAPI used hash codes to find prefabs.

Currently I have a net prefab that loads a inner prefab depending on if it is local.

private void Start()
{
if (this.isLocalPlayer)
{
//load fps model
}
else
{
//load tps model
}
}

I see. I think I have to separate these two types and have the former spawn the latter. Intuitively, this is backwards as this really is more of an is-a relationship rather than a has-a, but it seems to be the idiomatic approach.

Thanks for your help!