Need help for making Singleton style UObject and other problems.

Hello. I used to program in Cocos2D and Unity. I am developing a game in Unreal as new approach.

My project is 2D Chrono Trigger-ish (or Final Fantasy) with using a lot of Uflipbook.

The problems that I encounter, bugged me 2-3 days now. These question is very beginner-ish but I really need your help. Please…

1.I created C++ class inherited from UObject, and how do I create instance from it? I need to use it like Singleton.

I tried an actor object to “Construct Object” my singleton, and I cannot check whether it is instanced really or not.

I also tried Rama’s global access code

something is not enough to do what i want.

I need to use it from my Singleton during runtime too. Using value (or reference) from data in my Singleton…

2.Inside my UObject based Singleton, there are manager classes, which inherited from UObject. one of them is called Animation Manager,

which I used it to store a lot of Flipbooks by TMap (by accessing through UFUNCTION). The problem is… when my player actor use this Animation Manager’s flipbook

through my Singleton, it crashes my Unreal Engine, and I have to delete Binary folder in order to open Unreal Engine again.

Is there better way to implement sub manager class? and how to use it?

3.When I play the scene, GameMode1, GameNetworkManager1, and a lot of stuff pops out. I don’t really need them except camera, because as I explained above,

it is Chrono Trigger Style game, not FPS shooter. How do I disable them?

I am aware that I am asking a lot. I have been researching the Unreal Engine by myself and googling. those actions is not enough to get what I want.

Pretty Please. :stuck_out_tongue:

I use NewObject<Type>() to construct UObjects.
As for a singleton, I use my GameMode to store it and call through a static library.

There might be a better way, but for now this works.

New Object <Type>() UObject, GaneMode, that sounds interesting. But if I construct UObject, is it possible to check it by any mean necessary during run time?

In Project Settings > Engine > General Settings > Game Singleton Class you can actually set your own class derived from UObject. Maybe that would help?

I already did it too… but where can i check it during runtime though? anyway thank you for answer :slight_smile:

I’m not sure what you mean, just read and write to it?


USolusDataSingleton* USolusDataSingletonLibrary::GetSolusData(bool& IsValid)
{
	IsValid = false;
	**USolusDataSingleton* DataInstance = Cast<USolusDataSingleton>(GEngine->GameSingleton);**
 
	if(!DataInstance) return NULL;
	if(!DataInstance->IsValidLowLevel()) return NULL;
 
	IsValid = true;
	return DataInstance;
}

This gets you a pointer to thr UObject and then you can access whatever data you have in their. Structs or whatever.

My English is not mother tongue language, sorry about ambiguous reply. after coffee from a cafe, i will use your code to test it. Thank you So much for your attention.

hmmm… still in BP, it works, but when I hit Play Button, My Singleton is not valid… I dunno why. I even set my Singleton as Game Singleton Class in General Setting

Would probably need more specifics to help, some code, what you’re trying to do etc.

Would probably need more specifics to help, some code, what you’re trying to do etc.
[/QUOTE]

Okay after coffee break, i will submit my code

you can also inspect the game instance class for this purpose…

how can i inspect the game instance?

2016-04-13 (1).png

2016-04-13 (3).png

2016-04-13 (4).png


I did same as Rama code and I also modified (delete singleton sentence) DefaultEngine.ini.

why during runtime, my actor cannot get any data from my singleton (and where the heck is my singleton?).

Any suggestion?

Well one thing I see instantly is in the last screenshot you have nothing connected to the input pin of GetFolyeDeserterNonCombatAnimation? Never running like that.

You only need to delete the singleton declaration in the DefaultEngine.ini if you delete them and your editor crash at start well you need to edit manually the file.
Well reset your Singleton Object in your settings and try again, and do some debug stuff like get display name of your Singleton object, this will print something like “GameManagerBP6”, if it does your settings is ok :slight_smile:

I hope this help you ! :slight_smile:

okay let me fix it. uh… but why instance is not valid? hmmm… let me fix that Animation Function first

okay let me try ur advice :slight_smile: thanks

Yeah that would probably be if you removed the singleton from the DefaultEngine.ini.

how do i get display of my singleton? World Outliner does not display anything about it.

Okay. Gigantoad you are right. it was the problem with BP, but I face new problem, my animation does not show up… LOL XD anyway thank you so much guys