BepInEx / HarmonyX

Harmony built on top of MonoMod.RuntimeDetours with additional features
MIT License
373 stars 44 forks source link

Adding a prefab with BepInEx which can be instantiated by Photon? #119

Open StupidRepo opened 3 days ago

StupidRepo commented 3 days ago

Sorry if this issue doesn't fit here, I'm not really sure where to put it as it is kind of a BepInEx question and also a Photon Unity Networking (PUN) question.

Effectively, I'm trying to make an API for a multiplayer game where I can add items to the game and sync them across the network however (iirc) a prefab will need to be put in a specific folder for PUN (Resources, iirc?).

So, is it possible to make my own prefab instantiable by my plugin using PUN to sync it to others with the mod? I know I'll need an AssetBundle to hold the prefab but then I'm not really sure where to go from there. Other games I know with BepInEx custom item plugins don't use PUN (e.g. Lethal Company) so I wouldn't know any open source plugins I can 'borrow' code from...

ManlyMarco commented 3 days ago

You have to do it the same way as you would when making the game itself, have all people run the same code and resources so that the environments are all the same.

StupidRepo commented 3 days ago

What do you mean by that? Because what I'm saying is that the prefab itself needs to be physically in a folder in the Unity project, but as a simple modder with no access to the project then how can I add a prefab and register it to allow Photon not to complain?

Or am I being really stupid here? 😭

ManlyMarco commented 3 days ago

Just put it in an asset bundle and load it that way.

StupidRepo commented 3 days ago

But I thought PUN would only load things if it was in that special folder?

ManlyMarco commented 3 days ago

You can load ABs from wherever you want https://docs.unity3d.com/560/Documentation/ScriptReference/AssetBundle.LoadFromFile.html

StupidRepo commented 1 day ago

Yeah I know that but I'm pretty sure PUN has a weird restriction on networked prefabs from ABs. Maybe I'm wrong...

StupidRepo commented 19 hours ago
image

@ManlyMarco If you take a look, you can see (to instantiate a networked object), I would need to pass through a prefab name. Oh and, also:

Screenshot 2024-11-23 at 20 47 54

I guess I could make my own RPC instantiation, but why reinvent the wheel?