Skip to content

Instantly share code, notes, and snippets.

@TakaakiIchijo
Last active November 18, 2025 06:33
Show Gist options
  • Select an option

  • Save TakaakiIchijo/a2c69edd2d3a3afc67f971ec40160f3a to your computer and use it in GitHub Desktop.

Select an option

Save TakaakiIchijo/a2c69edd2d3a3afc67f971ec40160f3a to your computer and use it in GitHub Desktop.
Extension Unity MultiPlayerPlaymode, Get IsClone and Number of Instances
#if UNITY_EDITOR
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace NetcodeExtension
{
[InitializeOnLoad]
public static class MultiPlayerPlaymodeExtensions
{
public static readonly bool IsClone = false;
public static readonly int PlayerCount = 0;
static MultiPlayerPlaymodeExtensions()
{
//This Instance is Clone or not
var targetType = Type.GetType("Unity.Multiplayer.Playmode.VirtualProjects.Editor.VirtualProjectsEditor,Unity.Multiplayer.Playmode.VirtualProjects.Editor");
if (targetType == null)
{
Debug.LogError("Type VirtualProjectsEditor not found.");
}
var targetPropertyInfo = targetType?.GetProperty("IsClone", BindingFlags.Public | BindingFlags.Static);
if (targetPropertyInfo == null)
{
Debug.LogError("Event IsClone not found.");
}
if (targetPropertyInfo == null)
{
Debug.LogError("VirtualProjectsEditor IsClone property not found.");
}else {
IsClone = (bool)targetPropertyInfo.GetValue(null);
Debug.Log("VirtualPlayer.IsClone "+IsClone);
}
//VirtualProjects + Main count
targetType = Type.GetType("Unity.Multiplayer.Playmode.VirtualProjects.Editor.VirtualProjectsApi,Unity.Multiplayer.Playmode.VirtualProjects.Editor");
if (targetType == null)
{
Debug.LogError("Type VirtualProjectsEditor not found.");
}
var method = targetType?.GetMethod("GetProjects", BindingFlags.Public | BindingFlags.Static);
if (method == null)
{
Debug.LogError("method GetProjects not found.");
}else{
var result = new object[1] { "__all" };
if (result is Array arr)
{
PlayerCount = arr.Length + 1;
Debug.Log("Multiplayer Play Mode Player count "+PlayerCount);
}
}
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment