Scripting Questions

I’ve been converting a Unity project that I have to Flax, and am surprised at how straightforward it is.

Here are some of the errors that I haven’t been able to resolve and could use some help. Flax has come a long way from 1.0 to 1.5.

GetComponent<> is GetChild<>? I’ve tried various combinations of this but I always get an error

Unity has Hashcode.Combine() - does Flax have something similar? I’ve seen GetHashcode() but it’s not what I’m looking for

Is there an equivalent for Unity’s [SerializeField] private so that the property is visible in the editor (i.e. can I use [Serialize]?

LayerMask that can be selected in the editor (or is it just bit flags)

If what you are trying to find is an actor that is a child of whatever script you are calling the GetChild from the it should work. If you are just looking for another script then there should be a Actor.GetScript function . You can also share the errors you are getting.

[Serialize, ShowInEditor] you will have to use both right now if you want to show your private variable and have it serialize. But Flax also supports showing c# properties in the editor out of the box, I suggest using a public property to show something in the editor.

If you expose LayerMask member to the editor you will be able to pick your bits. There are some tricks you could use to get access to the physics layer masks if that is what you are after.

1 Like

I believe the HashCode one will not be available due to Flax 1.5 using the .NET Framework 4.5.2 and not .NET Core. Flax will be updating to .NET 7 for 1.6 update. I would think it would be available then.

1 Like

@ Tryibion,

Thank you very much for your help. With those clarifications I was able to fix more than half of the errors. I don’t think that I’ve got my head around the Actor/Component thing. This is where my Unreal/Unity baggage is a problem because there are some things that I need to unlearn.

Converting mouse clicks to world (RayCast wants a direction but that seems counter-intuitive for this use case) and new/Instantiate/Spawn are my biggest headaches right now, so I’ll try again tomorrow.

Thank you, again, for your responses. They really helped a lot.

1 Like

There is a good tutorial on converting mouse clicks to raycast in the docs https://docs.flaxengine.com/manual/scripting/tutorials/decal-on-mouse-click.html

1 Like

In Flax Engine you can use Actors and scripts. Scripts would be similar to what you would be used in in unity and actors are like the game objects. Flax Engine is designed around different components being their own actors instead of everything being scripts like in unity. You have a lot of freedom in the engine because you could design you systems as actors or scripts.

1 Like

Try go watching some of the videos on my channel, they should help you

1 Like

Awesome, thanks!

So, is it more like Unreal? That is, Actors are things placed in the scene and Scripts are components that get added to Actors?

Thanks, they were very helpful.

Not quite… they’re more like Nodes in Godot.

Actors are all objects of predefined types, meaning, and Actor can only be a camera, or only be a light, or only be a Rigid Body, etc. You can achieve a similar result to components in Unity and UE by parenting Actors in Flax.

2 Likes

Thank you. I’m not familiar with Godot but I understand your point.

But you can add as many scripts as you want to Actors.

1 Like

Any guidance on:
Spawning prefabs
Is there an Event system?
How can you determine if the mouse is over an Actor? The Script class doesn’t have an event for that
Would be greatly appreciated

Those are some good questions. Would you mind making a new topic for each one? That way, if anyone in the future also had those questions, they’d be able to find the answer easier. Thanks!

Sure, no problem

Does anyone know how to create a Visual Script for my Day and Night cycle to move automatically on its own ? I’m lost I make my sun position and etc.

Hello and welcome to the Flax Forums! I recommend starting a new thread for this.