Page 1 of 1

PlayerPortraits spawned with scripting show up with correct IProfile in Map Editor, but with a random one outside of it

Posted: Sat Dec 24, 2022 2:07 pm
by MCS
I have a simple script that creates a PlayerPortrait, and gives it a PlayerProfileInfo (by getting the appropriate IObjectPlayerProfileInfo from the map). This works fine in the editor, but if I start a game with this map, the portraits are randomized.
Things I've tried:
  • If I manually set the PlayerPortrait to use the profileinfo from the map, it works just fine. (However I need to be able to use scripts to change the playerprofileinfo)
  • If I set the Players skin to the profileinfo, it works--> It's not the PlayerProfileInfos getting randomized
  • If I check how many possible profiles the portrait has (.GetProfileInfos.Length), it returns 1 (which is correct), and if I don't add the profileinfo it is 0 (which is also what it should be)
Simple code to demonstrate:

Code: Select all

public void OnStartup() {
	IObjectPlayerPortrait portrait=(IObjectPlayerPortrait)Game.CreateObject("BgPlayerPortrait00");
	portrait.SetProfileInfo(Game.GetObject<IObjectPlayerProfileInfo>("profile"));
}
Create a blank world with an IObjectPlayerProfileInfo with a customid of "profile", and run this script to test.
Has anyone encountered anythin similar before? What could be causing it?

Re: PlayerPortraits spawned with scripting show up with correct IProfile in Map Editor, but with a random one outside of

Posted: Sun Dec 25, 2022 4:23 am
by Mighty Spirit the 2
That sounds exactly like a bug. Plenty of things that work in the editor, but if you are hosting a real game scripts can fail. Just like if you spawn a player via PlayerSpawnTrigger and set his FacingDirection to (-1), in the editor it works, but hosted game it will always face toward (1). If i recall correctly.
Or setting Primary and secondary Target with CameraAreaTrigger via script.
These things can cause you serious headaches and waste your time.

Re: PlayerPortraits spawned with scripting show up with correct IProfile in Map Editor, but with a random one outside of

Posted: Sun Dec 25, 2022 9:20 am
by Odex64
Technically it should work just fine if you're hosting an "offline" game too. Many things don't work due to synchronization issues I guess; in fact when hosting a server your PC behaves as a server AND client

But yeah, bugs like that were annoying when I used to script.