I have 2 characters in my game. A player and an enemy with BehaviorDesigner.
However the player (left) has instantiated all the correct items in its ItemSetManager unlike the enemy (right).
To create the enemy I did the followwing:
- I used the UCC character creator with AI Agent and NavMeshAgent enabled.
- Then I used the PUN integration script on it
- Removed the Respawner scripts
- Added BehaviorTreeAgent
- I have also tried with and without DemoAgent script supplied in the demo
I checked and both of their ItemSetManagers are being initialized in code.
It might also be worth noting that the player is being spawned with a SpawnBaseManager script, but the enemy is spawned with a custom script:
Is this the correct way to spawn a non-player object over PUN?
What am I missing to achieve a filled ItemSetManager like the one with the Player?
However the player (left) has instantiated all the correct items in its ItemSetManager unlike the enemy (right).
To create the enemy I did the followwing:
- I used the UCC character creator with AI Agent and NavMeshAgent enabled.
- Then I used the PUN integration script on it
- Removed the Respawner scripts
- Added BehaviorTreeAgent
- I have also tried with and without DemoAgent script supplied in the demo
I checked and both of their ItemSetManagers are being initialized in code.
It might also be worth noting that the player is being spawned with a SpawnBaseManager script, but the enemy is spawned with a custom script:
Is this the correct way to spawn a non-player object over PUN?
Code:
using Opsive.Shared.Game;
using Opsive.UltimateCharacterController.Networking.Game;
using Opsive.UltimateCharacterController.Utility;
using Photon.Pun;
using UnityEngine;
namespace Chib
{
public class SpawnEnemy: MonoBehaviour
{
[Tooltip("The enemy that should be spawned.")]
[SerializeField] protected GameObject m_Enemy;
[Tooltip("The positional offset that the object should be spawned.")]
[SerializeField] protected Vector3 m_PositionOffset;
[Tooltip("The rotational offset that the object should be spawned.")]
[SerializeField] protected Vector3 m_RotationOffset;
[Tooltip("Should the object be parented to the origin?")]
[SerializeField] protected bool m_ParentToOrigin;
private GameObject m_SpawnedObject;
public void Start() {
if (!PhotonNetwork.IsMasterClient) {
return;
}
if (m_Enemy == null) {
Debug.LogError("Error: An Enemy must be specified.");
return;
}
var position = MathUtility.TransformPoint(transform.position, transform.rotation, m_PositionOffset);
m_SpawnedObject = ObjectPool.Instantiate(m_Enemy, position, Quaternion.Euler(m_RotationOffset), m_ParentToOrigin ? transform : null);
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
NetworkObjectPool.NetworkSpawn(m_Enemy, m_SpawnedObject, false);
#endif
}
}
}
What am I missing to achieve a filled ItemSetManager like the one with the Player?