Coming from a Unity/Godot world, I’m a bit surprised that creating an actor dynamically is a persistent action. I would expect that whatever happened during a play session would be reverted once that session is stopped.
Am I trying to use Flax as if it was the other engines? What is the proper flow?
Also, the OnBeginPlayOnEndPlayOnEnabledOnDisabled keep being fired after each compilation, not when play starts/ends… I must be missing something here.
What I am trying to achieve is is having an Actor on the scene that once play starts, it spawns other Actors. Any explains is welcomed
Just to make sure, if you just want to make a script you will have to create a class that inherits from Script. What you are currently doing is creating a new Actor type (which is nothing wrong, just wanted to point that out in case you wanted to create a script instead).
If you want to go with a custom actor, you can do this:
public override void OnBeginPlay()
{
base.OnBeginPlay();
if (Engine.IsPlayMode)
{
AddChild<EmptyActor>();
}
}
to get your desired result (-> Extra Actor will be spawned on play mode enter/ when it is added to the scene and removed when exiting play mode, no actor spawned when actor is added to the scene during non play mode).
The Engine.IsPlayMode will be true in the editor if the editor is in play mode and false if not. Also it will always return true in a shipped game.
I think it is intentional that OnBeginPlay() is called in the editor as well (during non play mode), the comment text in the method body also says that:
I might be using Flax the same way I was using Godot… but my intension was indeed to create an Actor. One thing I love about that engine is the 1 node 1 functionality; something I would try to maintain while using Flax to the best of my ability.
if (Engine.IsPlayMode)
Was afraid the solution would be having a check like that one
I don’t believe there is a preprocessor (in C#) only available in play mode? Something that could be using in a Conditional attribute?
I don’t believe there is a preprocessor (in C#) only available in play mode? Something that could be using in a Conditional attribute?
There is one, but that will only differentiate between Editor and cooked game, not way to differentiate between play in editor and “editing in editor” mode:
Also yeah, I would keep the 1 actor/ node 1 functionality thing, but coming from Godot myself and now using Flax, I can tell you that sometimes it’s nice to have multiple scripts on one Actor, so don’t force yourself in that paradigm too much