playMaker

Author Topic: uNet and Set Property  (Read 1963 times)

Meka Games

  • Junior Playmaker
  • **
  • Posts: 57
uNet and Set Property
« on: February 25, 2019, 04:29:54 PM »
Hello. I created a poolsystem for my co-op multiplayer game by using this script: https://forum.unity.com/threads/networked-object-pool-example-for-unet-hlapi.369309/

and then i created this script to get work with this pool system. then i put this on my player object. And I invoked the method on a fsm state. Everything works fine on host and client if i set the spawnpoint or poolname before runtime.


Code: [Select]
using UnityEngine;
using UnityEngine.Networking;

public class PoolSpawn : NetworkBehaviour
{

public NetworkSpawnPool pool;
[SyncVar]
public string poolName;
[SyncVar]
public GameObject pooledObject;
[SyncVar]
public GameObject spawnPoint;
[SyncVar]
public Vector3 position;
[SyncVar]
public Vector3 rotation;
[SyncVar]
public GameObject storeObject;



[Command]
void CmdSpawn ()
{
        pool = NetworkSpawnPool.GetPoolByName(poolName);
var spawnObject = pool.ServerCreateFromPool (transform.position - transform.forward, Quaternion.identity);
if (spawnObject == null)
return;

var spawnPosition = Vector3.zero;
var spawnRotation = Vector3.zero;

if (spawnPoint != null) {
spawnPosition = spawnPoint.transform.position;


spawnPosition += position;

spawnRotation = spawnPoint.transform.eulerAngles;
} else {

spawnPosition = position;

spawnRotation = rotation;
}

spawnObject.transform.position = spawnPosition;
spawnObject.transform.rotation = Quaternion.Euler (spawnRotation);

storeObject = spawnObject;

pooledObject = spawnObject;

NetworkServer.Spawn (spawnObject);

}

}



BUT
I want to edit spawnpoint or pool name in each playmaker fsm. I have 15 different pools. And it's not working on host and client if i edit the pool name or any variable before the invoke method action. Nothings changing.



This is my first experience with multiplayer. Where am I doing wrong?
Thanks in advance.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: uNet and Set Property
« Reply #1 on: February 26, 2019, 03:15:53 AM »
Hi,

 if you are beginning with multiplayer, then you should not use uNet, this is a deprecated, sub system, full of bugs solution :)

you should go with PUN, and we provide full support for this:

 https://hutonggames.fogbugz.com/f/page?W928

Bye,

 Jean

Meka Games

  • Junior Playmaker
  • **
  • Posts: 57
Re: uNet and Set Property
« Reply #2 on: February 26, 2019, 03:54:50 AM »
Hi,

 if you are beginning with multiplayer, then you should not use uNet, this is a deprecated, sub system, full of bugs solution :)

you should go with PUN, and we provide full support for this:

 https://hutonggames.fogbugz.com/f/page?W928

Bye,

 Jean

I'm using uNet because i found a working pool system for multiplayer. I can't find the pool system for pun. Is there an example pool system for pun?

What can I do for this problem. I'm doing something wrong, but what?

Thanks.
« Last Edit: February 26, 2019, 03:57:55 AM by haratman »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: uNet and Set Property
« Reply #3 on: February 27, 2019, 01:51:34 AM »
Hi,

 pool systems is available for Pun, you can find a working sample here:

https://github.com/jeanfabre/Exitgames--PUN--Pooling_u4

it's old but still relevant because the technic is the same regardless of the pooling asset you use.

 also, I think that pooling inside multi player system is really a corner case, you are going to instanciate 4-5 players max, I don't think it is that critical to use uNet over pun just because of pooling.

 if you are firing bullets, then your network problems will be far more important in termns of playability than the cost of instantiating these bullets without a pool.

so all in all, this is a bad idea to use uNet because it's deprecated.

If you are on mobile, the problem could be that you need to create a linker file to let Unity know what you'll be reflecting at runtime so that it's not removed from the build: http://hutonggames.com/playmakerforum/index.php?topic=11126.0

else, if you are able to code, always prefer creating proper actions instead of using Reflection ( setproperty, invokeMethod,CallMethod, etc), this will be more effective and robust.

Bye,

 Jean


Meka Games

  • Junior Playmaker
  • **
  • Posts: 57
Re: uNet and Set Property
« Reply #4 on: February 27, 2019, 11:29:21 AM »
Hi,

 pool systems is available for Pun, you can find a working sample here:

https://github.com/jeanfabre/Exitgames--PUN--Pooling_u4

it's old but still relevant because the technic is the same regardless of the pooling asset you use.

 also, I think that pooling inside multi player system is really a corner case, you are going to instanciate 4-5 players max, I don't think it is that critical to use uNet over pun just because of pooling.

 if you are firing bullets, then your network problems will be far more important in termns of playability than the cost of instantiating these bullets without a pool.

so all in all, this is a bad idea to use uNet because it's deprecated.

If you are on mobile, the problem could be that you need to create a linker file to let Unity know what you'll be reflecting at runtime so that it's not removed from the build: http://hutonggames.com/playmakerforum/index.php?topic=11126.0

else, if you are able to code, always prefer creating proper actions instead of using Reflection ( setproperty, invokeMethod,CallMethod, etc), this will be more effective and robust.

Bye,

 Jean

Hello.

Now I'm using PUN for my project. I downloaded this PUN pooling but i got this error:
Code: [Select]
Assets/PUN Custom Samples/PoolManager/Scripts/PunPoolManagerBridge.cs(5,7): error CS0246: The type or namespace name `PathologicalGames' could not be found. Are you missing an assembly reference?

And SmartPool is no longer available on the unity asset store. What to do?
Thanks.
« Last Edit: February 27, 2019, 11:31:53 AM by haratman »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: uNet and Set Property
« Reply #5 on: February 28, 2019, 01:49:19 AM »
Hi,

 You need to inspire from the script itself. I don't have a copy of

here's the script removed from any poo system, so you can plug yours

Code: [Select]
using System.Collections.Generic;
using UnityEngine;
using System.Collections;

//using PathologicalGames;

/// <summary>
/// Pun PoolManager bridge.
/// Common Pitfalls:
/// -- even when using a pool manager, you need to store your prefab inside a Resources Folder,
///    it's because PUN needs to load the prefab and assign viewIDs to all PhotonViews. Note: It's not instantiated by pun at all, just loaded for analyzing.
/// -- on the instanciated prefab, use OnPhotonInstantiate() to catch info on initializating if you must, OnEnable and Start aren't suitable due to the network initializaion processes.
/// </summary>
public class PunPoolManagerBridge : MonoBehaviour, IPunPrefabPool
{
public void Start ()
{
    PhotonNetwork.PrefabPool = this;
}

    public GameObject Instantiate(string prefabId, Vector3 position, Quaternion rotation)
    {
Debug.LogWarning("Instantiate Prefab: " + prefabId);

GameObject go;// =  PoolManager.Pools["Pool"].Spawn(prefabId).gameObject ;
        go.transform.position = position;
        go.transform.rotation = rotation;

        return go;
    }

    public void Destroy(GameObject gameObject)
    {

//PoolManager.Pools["Pool"].Despawn(gameObject.transform);
    }
}

Bye,

 Jean