UGUI MiniMap Dynamically set Target

General support.
Post Reply
User avatar
SureSight
New Member
New Member
Posts: 7
Joined: Wed Dec 16, 2015 4:35 am

The nature of our game and the way we spawn the player and switch between other playable characters means that we need to set the MiniMap.Target manually.
However, this is a readonly property at the moment.

Any chance of a fix to allow us to update the MiniMap.Target?
User avatar
Lovatto
Admin
Admin
Posts: 1772
Joined: Sun Dec 07, 2014 3:18 pm
Contact:

You can use the public variable: m_Target;
like: CODE: csharp
bl_MiniMapUtils.GetMiniMap().m_Target = MyPlayerTarget;
How to find your Invoice Number: Here
How to find your Order Number: Here
User avatar
SureSight
New Member
New Member
Posts: 7
Joined: Wed Dec 16, 2015 4:35 am

Oops. I saw that this was named as private member and did not even check the visibility modifier.
Thanks!
User avatar
Shawn67
New Member
New Member
Posts: 1
Joined: Wed Dec 30, 2015 11:47 pm

I was coming here to report the same issue along with my fix. But in seeing this post, I went to try to do this in another script first. I run into this similar issue with any assets that require dragging a player prefab into the inspector. I am currently using the ORK rpg framework but had the same issues with RPG Kit and other frameworks that instantiate the player at runtime.

So to try your fix I created the following small C# script and then attach it to the MiniMap2D object in my hierarchy in order to find my player character which will always be tagged as "Player":

Code: Select all

public class myMinimapTarget : MonoBehaviour {

	// Use this for initialization
	void Start() {
        bl_MiniMapUtils.GetMiniMap().m_Target = GameObject.FindGameObjectWithTag("Player");
    }
}
At first I tried to do it using the Awake() function but I think it was trying to run before ORK had actually instantiated the player character. Once I moved it to Start it works like a charm - even when changing scenes and a new map is loaded. Are all the fields from the inspector available in the same way? I'm wondering if I could use my new script as a minimap manager in order to also set the map name and map description as well. That way I can pretty much just drag that prefab into the scene and let it set those based on scene values that I have in ORK.

Also, before I forget, I want to thank you for making this asset. This is the fourth one that I have tried. It is the FIRST one that has pretty much worked flawlessly out of the box. The only problem I had with it was the one above and like I said, I'm finding that pretty much standard with assets that deal with wanting the player prefab. So THANK YOU! :)
User avatar
MoGrammerInCS
New Member
New Member
Posts: 1
Joined: Sun Mar 06, 2016 9:24 pm

To start off, I'd like to say that what you have here for an "out of the box" asset is fantastic.

The only issue that I have... *had* is with networking and instantiated players. To your credit I'm certain the problems that I have endured is the lack of my programming skill.
even with the post, and the code on the forum after 2 days I just cannot get this to work...


So in essence all I did was added,

Camera cam = (Camera.main != null) ? Camera.main : Camera.current;
if (cam == null) {
m_Target = GameObject.FindGameObjectWithTag("Player");
on lines 173-175.

It seemed to help except that the MiniMap is always looking for "Target"..

as bad as this will sound, I created my Player Prefab, Disabled a few lines of code, and placed the "MiniMapCamera" as a child of my Player Prefab.

Each time the players are instantiated, the miniMapcamera is invoked and everything seems to work wonderfully.

Additionally, the MiniMap is Disabled in the hierarchy at instantiate. - Downside is you have to hotkey the map to open it. (though typing this out, I could add a script with WaitForSeconds(15) and it will become active in the hierarchy). Might give that a try.


In closing, you guys that made this are fantastic. I appreciate your work and wanted to say thank you ~ from the people that aren't C# savvy. If you would want to post something on the forum here that's the Proper way to do it... I'd be ever so thankful.

Thanks again!
Best wishes, and good luck!
User avatar
mjdj1999
New Member
New Member
Posts: 5
Joined: Sat Apr 28, 2018 9:28 am

Lovatto wrote: Thu Dec 17, 2015 10:18 pm You can use the public variable: m_Target;
like: CODE: csharp
bl_MiniMapUtils.GetMiniMap().m_Target = MyPlayerTarget;
Maybe my blood sugar is low but I'm having difficulties trying to figure out what file/ script to put this in:

Code: Select all

bl_MiniMapUtils.GetMiniMap().m_Target = MyPlayerTarget;
I would think (with this being an official add-on) that the tutorial could somehow add that line of code into your character. I would understand if you already had a player but with minimap being an add-on, it would just add it for you (as the player is obviously not in the hiearchy). The tutorial for this is for your own game (without MFPS).
User avatar
Lovatto
Admin
Admin
Posts: 1772
Joined: Sun Dec 07, 2014 3:18 pm
Contact:

Yes, if you are using the addon version you don't have to do this integration, just enable the addon click and on the Integration MenuItem and that's.
How to find your Invoice Number: Here
How to find your Order Number: Here
User avatar
hersa
New Member
New Member
Posts: 7
Joined: Fri Jul 31, 2020 9:04 pm

Lovatto wrote: Fri Feb 14, 2020 12:31 pm Yes, if you are using the addon version you don't have to do this integration, just enable the addon click and on the Integration MenuItem and that's.
I have enabled it, but why is it still not working? I still receive error: "NullReferenceException: Object reference not set to an instance of an object (bl_MiniMap.cs:170)"
Post Reply