Search Unity

Feedback Request to remove trying to spawn an owner predicted ghost which does not have a valid owner set err

Discussion in 'NetCode for ECS' started by optimise, May 27, 2023.

  1. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    I request to remove error since I have pipeline to spawn ghost that need to be consistent for both owner predicted ghost and interpolated ghost. Currently it's kind of gross that I need to purposely create a if else code path just to tackle this error to pass -1 NetworkId.

    Trying to spawn an owner predicted ghost which does not have a valid owner set. When using owner prediction you must set GhostOwner.NetworkId when spawning the ghost. If the ghost is not owned by a player you can set NetworkId to -1.
    UnityEngine.Debug:LogError (object)
    Unity.Logging.Sinks.ManagedUnityEngineDebugLogWrapper:WriteFunc (Unity.Logging.LogLevel,byte*,int) (at ./Library/PackageCache/com.unity.logging@1.0.8/Runtime/TestSinks/UnityDebugLogSink.cs:154)
     
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    900
    I really don't want to remove the error, because spawning an owner predicted ghost requires a choice: or he has a valid owner or should be set to -1.
    Otherwise we can't discern if you forgot to initialise the owner with a correct value.
    What if I can give you another choice: that is to setup this on the prefab itself (as option) ?
     
  3. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    Not really sure what u mean by setup this on the prefab itself (as option) but currently there's hasOwner boolean toggle at ghost authoring component baker that can't solve the error since it just toggle true will add GhostOwner component else won't add the component. The reason behind it is currently it will just log the error when npc caster ghost which is interpolated ghost with network id = 0 trying to spawn ghost which has GhostOwner component meanwhile owner predicted ghost also need to spawn the same ghost which has GhostOwner component. So I need a generic path for caster ghost to just pass in caster ghost self GhostOwner network id to spawn ghost that set Ghost owner component. I no need to care whether caster ghost is owner predicted ghost or interpolated ghost need to set whatever network id value or -1. Another use case is sometimes the caster ghost own by player sometimes it's not that u need a generic path to spawn ghost with GhostOwner component. The netcode needs to auto handle it and won't log error. Not sure how u going to solve this problem but I guess can make it when caster ghost dun have player owner it will auto set self GhostOwner network id to -1 and change back to positive GhostOwner network id when the caster ghost has player owner.
     
    Last edited: May 28, 2023
  4. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    900
    When I mentioned to give an option on the prefab, was to add another toggle or give more options for the ownership and we can have an opportunity to check if that prefab requires an owner to be set.

    I.e at that point we know what you want to do and we can just set that value to -1 (or consider 0 already as a valid case) at baking time and that would give enough context to understand the fact having for OwnerPredicted ghost no owner for that prefab/ghost is a valid use case.

    Then the obvious question the is: when and how do you assign that ownership? Never? And in case you do, how you distinguish which specific caster/ghost entity need to be assigned to a specific player?
    I imagine you have logic for that.

    I'm asking because not an assigning an owner to a OnwerPredicted ghost, change how the entity is spawned on the client side. It is classified as interpolated ghost, and as such, delayed (based on the interpolation delay) and predicted components removed.
    Even if the server assign an owner later on, this will not automatically "convert" that ghost to predicted for the owner. It is necessary to manually detect that condition and use prediction switching to handle it. So be aware of all these.
     
    optimise likes this.
  5. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    Oh. Maybe u misunderstand what I want to say or I miss something. Currently I have owner predicted caster ghost that owned by a player is working properly that no error log when spawning ghost that has GhostOwner. For interpolated caster ghost as npc that not owned by any player will log error when spawning ghost with GhostOwner. What I expect is since interpolated caster ghost is completely run and control by server and client totally has no control to the interpolated caster ghost, it should not log error by default. But still I think the toggle u proposed should solve my problem. I just think that by default it should not log error for the ghost that is fully controlled by server since server has authorization to control any ghost to cast any ghost with GhostOwner without error log. After solving this limitation, I think it's no longer required to have the toggle anymore. Btw I guess current netcode dun have mechanism to handle npc ghost (i.e. ghost that has no player owner) to spawn ghost that has OwnerGhost without error log?

    One more thing. I think it's better to just remove HasOwner toggle at ghost authoring component baker and add GhostOwner to all the ghost by default or still keep HasOwner toggle but make GhostOwner as enableable component as disable state when toggle is false to make it try to merge most ghosts into same archetype.

    Ya. Somehow I know that at client side it won't magically become owner predicted ghost. For the use case that sometimes owned by player sometimes not, I dun have this use case for now but I mentioned it just in case someone might need it. I think after solving the problem mentioned previously should solve this problem too since it's also a npc ghost when there's no player owner.
     
    Last edited: May 28, 2023
  6. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    Ignore my previous post. I try to make it shorter and simple. The toggle solution u proposed can solve my problem but I would like this problem to be solved much better way and enable more use case. What I expect is when there's spawned character ghost that has no owner holding by client player that basically can say is npc, the character ghost should able to spawn any ghost without log any error since technically the character ghost is fully controlled by server and no client player controls this character ghost. When the character ghost is owner by client player again then the error will log again when spawning invalid ghost owner number. Not sure how u going to solve this problem in better way but I think one possible solution is make the server automatically set that ghost owner component to -1 when the character ghost has no owner holding by client player to solve the error log problem.